func cmdCat(subFlags *flag.FlagSet, args []string) error { var ( longListing = subFlags.Bool("l", false, "long listing") force = subFlags.Bool("f", false, "no warning on nonexistent node") ) subFlags.Parse(args) if subFlags.NArg() == 0 { return fmt.Errorf("cat: no path specified") } resolved, err := zk.ResolveWildcards(zconn, subFlags.Args()) if err != nil { return fmt.Errorf("cat: invalid wildcards: %v", err) } if len(resolved) == 0 { // the wildcards didn't result in anything, we're done return nil } hasError := false for _, arg := range resolved { zkPath := fixZkPath(arg) data, _, err := zconn.Get(zkPath) if err != nil { hasError = true if !*force || !zookeeper.IsError(err, zookeeper.ZNONODE) { log.Warningf("cat: cannot access %v: %v", zkPath, err) } } else { if *longListing { fmt.Printf("%v:\n", zkPath) } fmt.Print(data) if len(data) > 0 && data[len(data)-1] != '\n' && (terminal.IsTerminal(os.Stdout.Fd()) || *longListing) { fmt.Print("\n") } } } if hasError { return fmt.Errorf("cat: some paths had errors") } return nil }
func cmdCat(args []string) { if len(args) == 0 { log.Fatal("cat: no path specified") } args, err := zk.ResolveWildcards(zconn, args) if err != nil { log.Fatalf("cat: invalid wildcards: %v", err) } if len(args) == 0 { // the wildcards didn't result in anything, we're done return } hasError := false for _, arg := range args { zkPath := fixZkPath(arg) data, _, err := zconn.Get(zkPath) if err != nil { hasError = true if !*force || !zookeeper.IsError(err, zookeeper.ZNONODE) { log.Printf("cat: cannot access %v: %v", zkPath, err) } } else { if *longListing { fmt.Printf("%v:\n", zkPath) } fmt.Print(data) if len(data) > 0 && data[len(data)-1] != '\n' && (terminal.IsTerminal(os.Stdout.Fd()) || *longListing) { fmt.Print("\n") } } } if hasError { os.Exit(1) } }