-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Persson
committed
Sep 24, 2015
1 parent
028364b
commit b74e18a
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
etcd "github.com/coreos/go-etcd/etcd" | ||
|
||
"github.com/mickep76/common" | ||
) | ||
|
||
// Tree | ||
func Tree(root *etcd.Node, indent string) { | ||
for _, n := range root.Nodes { | ||
keys := strings.Split(n.Key, "/") | ||
k := keys[len(keys)-1] | ||
if n.Dir { | ||
fmt.Printf("%s├── %s/\n", indent, k) | ||
Tree(n, indent+"│ ") | ||
} else { | ||
fmt.Printf("%s├── %s\n", indent, k) | ||
} | ||
} | ||
} | ||
|
||
/* | ||
├── postfix | ||
│ ├── LICENSE | ||
│ ├── TLS_LICENSE | ||
│ ├── access | ||
│ ├── aliases | ||
*/ | ||
|
||
func main() { | ||
// Options. | ||
version := flag.Bool("version", false, "Version") | ||
peers := flag.String("peers", common.GetEnv(), "Comma separated list of etcd nodes") | ||
dir := flag.String("dir", "", "etcd directory") | ||
flag.Parse() | ||
|
||
// Print version. | ||
if *version { | ||
fmt.Printf("etcd-import %s\n", common.Version) | ||
os.Exit(0) | ||
} | ||
|
||
// Validate input. | ||
if *dir == "" { | ||
log.Fatalf("You need to specify etcd dir.") | ||
} | ||
|
||
// Setup etcd client. | ||
client := etcd.NewClient(strings.Split(*peers, ",")) | ||
|
||
// Export data. | ||
res, err := client.Get(*dir, true, true) | ||
if err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
|
||
fmt.Println(strings.TrimRight(*dir, "/") + "/") | ||
Tree(res.Node, "") | ||
} |