func (c *fixvCmd) run(args []string) (tofix []string, err error) { var vendoredFiles []string if len(args) != 0 { vendoredFiles = args } else { repo, err := repoRoot() if err != nil { return nil, err } if !strings.HasSuffix(repo, string(filepath.Separator)) { repo += string(filepath.Separator) } out, err := cmdOutputDirErr(".", "git", "diff-index", "--name-only", "--diff-filter=ACM", "--cached", "HEAD", "--") if err != nil { return nil, err } vendoredFiles = addRoot(repo, filter(isVendored, nonBlankLines(out))) if len(vendoredFiles) == 0 { return nil, nil } } re := regexp.MustCompile(`("` + strings.Join(vendoredNames, `/|"`) + `/)`) for _, filename := range vendoredFiles { data, err := ioutil.ReadFile(filename) if err != nil { return nil, err } if m := re.Find(data); m == nil { continue } if !c.fix { cmdmain.Errorf("%v imports need fixing\n", filename) tofix = append(tofix, filename) continue } for _, importName := range vendoredNames { re := regexp.MustCompile(`"(` + importName + "/)") data = re.ReplaceAll(data, []byte(`"`+vendoringPath+`$1`)) } if err := ioutil.WriteFile(filename, data, 0600); err != nil { return nil, fmt.Errorf("failed to write modified file %v: %v", filename, err) } cmdmain.Errorf("%v imports now fixed\n", filename) } if !c.fix && len(tofix) > 0 { return tofix, errImportsNeedsFixing } return nil, nil }
func exitf(format string, args ...interface{}) { if !strings.HasSuffix(format, "\n") { format = format + "\n" } cmdmain.Errorf(format, args) cmdmain.Exit(1) }
func formattedSearchHelp() { s := search.SearchHelp() type help struct{ Name, Description string } h := []help{} err := json.Unmarshal([]byte(s), &h) if err != nil { cmdmain.Errorf("%v", err) os.Exit(1) } w := new(tabwriter.Writer) w.Init(cmdmain.Stdout, 0, 8, 0, '\t', 0) fmt.Fprintln(w, "Predicates for search expressions") fmt.Fprintln(w) fmt.Fprintln(w, "Predicate\tDescription") fmt.Fprintln(w) for _, predicate := range h { desc := strings.Split(predicate.Description, "\n") for i, d := range desc { if i == 0 { fmt.Fprintf(w, "%s\t%s\n", predicate.Name, d) } else { fmt.Fprintf(w, "\t%s\n", d) } } } w.Flush() }
func handleResult(what string, pr *client.PutResult, err error) error { if err != nil { cmdmain.Errorf("Error putting %s: %s\n", what, err) cmdmain.ExitWithFailure = true return err } fmt.Fprintln(cmdmain.Stdout, pr.BlobRef.String()) return nil }
func printf(format string, args ...interface{}) { cmdmain.Errorf(format, args...) }
func (c *attrCmd) Usage() { cmdmain.Errorf("Usage: camput [globalopts] attr [attroption] <permanode> <name> <value>") }
func (c *permanodeCmd) Usage() { cmdmain.Errorf("Usage: camput [globalopts] permanode [permanodeopts]\n") }
func (c *rawCmd) Usage() { cmdmain.Errorf("Usage: camput [globalopts] rawobj [rawopts]\n") }
func (c *fixvCmd) Usage() { cmdmain.Errorf("Usage: devcam [globalopts] fixv [args...]\n") }
func (c *deleteCmd) Usage() { cmdmain.Errorf("Usage: camput [globalopts] delete <blobref1> [blobref2]...") }
func (c *searchDocCmd) Usage() { cmdmain.Errorf("camtool searchdoc") }