diff --git a/cmd/cue/cmd/common.go b/cmd/cue/cmd/common.go index ea7a8a8f4f1..f39947cfb39 100644 --- a/cmd/cue/cmd/common.go +++ b/cmd/cue/cmd/common.go @@ -68,10 +68,6 @@ var defaultConfig = config{ var inTest = false -func exitIfErr(cmd *Command, inst *cue.Instance, err error, fatal bool) { - exitOnErr(cmd, err, fatal) -} - func getLang() language.Tag { loc := os.Getenv("LC_ALL") if loc == "" { @@ -108,7 +104,7 @@ func exitOnErr(cmd *Command, err error, fatal bool) { } } -func loadFromArgs(cmd *Command, args []string, cfg *load.Config) []*build.Instance { +func loadFromArgs(args []string, cfg *load.Config) []*build.Instance { binst := load.Instances(args, cfg) if len(binst) == 0 { return nil @@ -376,7 +372,7 @@ type config struct { loadCfg *load.Config } -func newBuildPlan(cmd *Command, args []string, cfg *config) (p *buildPlan, err error) { +func newBuildPlan(cmd *Command, cfg *config) (p *buildPlan, err error) { if cfg == nil { cfg = &defaultConfig } @@ -400,9 +396,7 @@ func newBuildPlan(cmd *Command, args []string, cfg *config) (p *buildPlan, err e } cfg.reFile = re - if err := setTags(cfg.loadCfg, cmd.Flags(), cmd.Parent().Flags()); err != nil { - return nil, err - } + setTags(cfg.loadCfg, cmd.Flags(), cmd.Parent().Flags()) return p, nil } @@ -411,7 +405,7 @@ func (p *buildPlan) matchFile(file string) bool { return p.cfg.reFile.MatchString(file) } -func setTags(cfg *load.Config, flags ...*pflag.FlagSet) error { +func setTags(cfg *load.Config, flags ...*pflag.FlagSet) { // setTags usually receives a subcommmand's flags, plus the parent (root) command's flags, // so that we can support "cue cmd -t foo=bar mycmd" as well as the short form "cue -t foo=bar mycmd". // TODO: once we remove "cue cmd" short-hand support, go back to a single FlagSet parameter. @@ -422,7 +416,6 @@ func setTags(cfg *load.Config, flags ...*pflag.FlagSet) error { cfg.TagVars = load.DefaultTagVars() } } - return nil } type decoderInfo struct { @@ -523,14 +516,14 @@ func (p *buildPlan) importFiles(b *build.Instance) error { } func parseArgs(cmd *Command, args []string, cfg *config) (p *buildPlan, err error) { - p, err = newBuildPlan(cmd, args, cfg) + p, err = newBuildPlan(cmd, cfg) if err != nil { return nil, err } adt.DebugSort, _ = strconv.Atoi(os.Getenv("CUE_DEBUG_SORT_ARCS")) - builds := loadFromArgs(cmd, args, cfg.loadCfg) + builds := loadFromArgs(args, cfg.loadCfg) if builds == nil { return nil, errors.Newf(token.NoPos, "invalid args") } @@ -727,7 +720,7 @@ func buildInstances(cmd *Command, binst []*build.Instance, ignoreErrors bool) [] // If there are no files and User is true, then use those? // Always use all files in user mode? instances, err := cmd.ctx.BuildInstances(binst) - exitIfErr(cmd, nil, err, true) + exitOnErr(cmd, err, true) insts := make([]*instance, len(instances)) for i, v := range instances { @@ -747,12 +740,12 @@ func buildInstances(cmd *Command, binst []*build.Instance, ignoreErrors bool) [] for _, inst := range instances { // TODO: consider merging errors of multiple files, but ensure // duplicates are removed. - exitIfErr(cmd, nil, inst.Validate(), !flagIgnore.Bool(cmd)) + exitOnErr(cmd, inst.Validate(), !flagIgnore.Bool(cmd)) } return insts } -func buildToolInstances(cmd *Command, binst []*build.Instance) ([]*cue.Instance, error) { +func buildToolInstances(binst []*build.Instance) ([]*cue.Instance, error) { instances := cue.Build(binst) for _, inst := range instances { if inst.Err != nil { @@ -774,11 +767,9 @@ func buildTools(cmd *Command, args []string) (*cue.Instance, error) { Tools: true, } f := cmd.cmd.Flags() - if err := setTags(cfg, f, cmd.cmd.Parent().Flags()); err != nil { - return nil, err - } + setTags(cfg, f, cmd.cmd.Parent().Flags()) - binst := loadFromArgs(cmd, args, cfg) + binst := loadFromArgs(args, cfg) if len(binst) == 0 { return nil, nil } @@ -801,7 +792,7 @@ func buildTools(cmd *Command, args []string) (*cue.Instance, error) { inst.Files = inst.Files[:k] } - insts, err := buildToolInstances(cmd, binst) + insts, err := buildToolInstances(binst) if err != nil { return nil, err } diff --git a/cmd/cue/cmd/custom.go b/cmd/cue/cmd/custom.go index fcd041234d2..b921c972741 100644 --- a/cmd/cue/cmd/custom.go +++ b/cmd/cue/cmd/custom.go @@ -154,7 +154,7 @@ func doTasks(cmd *Command, typ, command string, root *cue.Instance) error { c := flow.New(cfg, root, newTaskFunc(cmd)) err := c.Run(context.Background()) - exitIfErr(cmd, root, err, true) + exitOnErr(cmd, err, true) return err } diff --git a/cmd/cue/cmd/fmt.go b/cmd/cue/cmd/fmt.go index 9f5b0a96eea..85333afb9b1 100644 --- a/cmd/cue/cmd/fmt.go +++ b/cmd/cue/cmd/fmt.go @@ -34,7 +34,7 @@ func newFmtCmd(c *Command) *cobra.Command { Long: `Fmt formats the given files or the files for the given packages in place `, RunE: mkRunE(c, func(cmd *Command, args []string) error { - plan, err := newBuildPlan(cmd, args, &config{loadCfg: &load.Config{ + plan, err := newBuildPlan(cmd, &config{loadCfg: &load.Config{ Tests: true, Tools: true, AllCUEFiles: true, @@ -42,7 +42,7 @@ func newFmtCmd(c *Command) *cobra.Command { }}) exitOnErr(cmd, err, true) - builds := loadFromArgs(cmd, args, plan.cfg.loadCfg) + builds := loadFromArgs(args, plan.cfg.loadCfg) if builds == nil { exitOnErr(cmd, errors.Newf(token.NoPos, "invalid args"), true) } diff --git a/cmd/cue/cmd/get_go.go b/cmd/cue/cmd/get_go.go index a2ecdec6ff2..5070aa26926 100644 --- a/cmd/cue/cmd/get_go.go +++ b/cmd/cue/cmd/get_go.go @@ -367,7 +367,7 @@ func extract(cmd *Command, args []string) error { // command specifies a Go package(s) that belong to the main module // and where for some reason the // determine module root: - binst := loadFromArgs(cmd, []string{"."}, nil)[0] + binst := loadFromArgs([]string{"."}, nil)[0] // TODO: require explicitly set root. root := binst.Root diff --git a/cmd/cue/cmd/trim.go b/cmd/cue/cmd/trim.go index 5424318df27..370d36549f4 100644 --- a/cmd/cue/cmd/trim.go +++ b/cmd/cue/cmd/trim.go @@ -92,7 +92,7 @@ removal. } func runTrim(cmd *Command, args []string) error { - binst := loadFromArgs(cmd, args, nil) + binst := loadFromArgs(args, nil) if binst == nil { return nil }