()
| 91 | ) |
| 92 | |
| 93 | func init() { |
| 94 | // Config files can enable experiments which alter the availability and/or |
| 95 | // behavior of some flags, so we need to parse the experiments before the |
| 96 | // flags. However, we need the --taskfile and --dir flags before we can |
| 97 | // parse the experiments as they can alter the location of the config files. |
| 98 | // Because of this circular dependency, we parse the flags twice. First, we |
| 99 | // get the --taskfile and --dir flags, then we parse the experiments, then |
| 100 | // we parse the flags again to get the full set. We use a flagset here so |
| 101 | // that we can parse a subset of flags without exiting on error. |
| 102 | var dir, entrypoint string |
| 103 | fs := pflag.NewFlagSet("experiments", pflag.ContinueOnError) |
| 104 | fs.StringVarP(&dir, "dir", "d", "", "") |
| 105 | fs.StringVarP(&entrypoint, "taskfile", "t", "", "") |
| 106 | fs.Usage = func() {} |
| 107 | _ = fs.Parse(os.Args[1:]) |
| 108 | |
| 109 | // Parse the experiments |
| 110 | dir = cmp.Or(dir, filepath.Dir(entrypoint)) |
| 111 | |
| 112 | config, _ := taskrc.GetConfig(dir) |
| 113 | experiments.ParseWithConfig(dir, config) |
| 114 | |
| 115 | // Parse the rest of the flags |
| 116 | log.SetFlags(0) |
| 117 | log.SetOutput(os.Stderr) |
| 118 | pflag.Usage = func() { |
| 119 | log.Print(usage) |
| 120 | pflag.PrintDefaults() |
| 121 | } |
| 122 | |
| 123 | pflag.BoolVar(&Version, "version", false, "Show Task version.") |
| 124 | pflag.BoolVarP(&Help, "help", "h", false, "Shows Task usage.") |
| 125 | pflag.BoolVarP(&Init, "init", "i", false, "Creates a new Taskfile.yml in the current folder.") |
| 126 | pflag.StringVar(&Completion, "completion", "", "Generates shell completion script.") |
| 127 | pflag.BoolVarP(&List, "list", "l", false, "Lists tasks with description of current Taskfile.") |
| 128 | pflag.BoolVarP(&ListAll, "list-all", "a", false, "Lists tasks with or without a description.") |
| 129 | pflag.BoolVarP(&ListJson, "json", "j", false, "Formats task list as JSON.") |
| 130 | pflag.StringVar(&TaskSort, "sort", "", "Changes the order of the tasks when listed. [default|alphanumeric|none].") |
| 131 | pflag.BoolVar(&Status, "status", false, "Exits with non-zero exit code if any of the given tasks is not up-to-date.") |
| 132 | pflag.BoolVar(&NoStatus, "no-status", false, "Ignore status when listing tasks as JSON") |
| 133 | pflag.BoolVar(&Nested, "nested", false, "Nest namespaces when listing tasks as JSON") |
| 134 | pflag.BoolVar(&Insecure, "insecure", getConfig(config, "REMOTE_INSECURE", func() *bool { return config.Remote.Insecure }, false), "Forces Task to download Taskfiles over insecure connections.") |
| 135 | pflag.BoolVarP(&Watch, "watch", "w", false, "Enables watch of the given task.") |
| 136 | pflag.BoolVarP(&Verbose, "verbose", "v", getConfig(config, "VERBOSE", func() *bool { return config.Verbose }, false), "Enables verbose mode.") |
| 137 | pflag.BoolVarP(&Silent, "silent", "s", getConfig(config, "SILENT", func() *bool { return config.Silent }, false), "Disables echoing.") |
| 138 | pflag.BoolVar(&DisableFuzzy, "disable-fuzzy", getConfig(config, "DISABLE_FUZZY", func() *bool { return config.DisableFuzzy }, false), "Disables fuzzy matching for task names.") |
| 139 | pflag.BoolVarP(&AssumeYes, "yes", "y", getConfig(config, "ASSUME_YES", func() *bool { return nil }, false), "Assume \"yes\" as answer to all prompts.") |
| 140 | pflag.BoolVar(&Interactive, "interactive", getConfig(config, "INTERACTIVE", func() *bool { return config.Interactive }, false), "Prompt for missing required variables.") |
| 141 | pflag.BoolVarP(&Parallel, "parallel", "p", false, "Executes tasks provided on command line in parallel.") |
| 142 | pflag.BoolVarP(&Dry, "dry", "n", getConfig(config, "DRY", func() *bool { return nil }, false), "Compiles and prints tasks in the order that they would be run, without executing them.") |
| 143 | pflag.BoolVar(&Summary, "summary", false, "Show summary about a task.") |
| 144 | pflag.BoolVarP(&ExitCode, "exit-code", "x", false, "Pass-through the exit code of the task command.") |
| 145 | pflag.StringVarP(&Dir, "dir", "d", "", "Sets the directory in which Task will execute and look for a Taskfile.") |
| 146 | pflag.StringVarP(&Entrypoint, "taskfile", "t", "", `Choose which Taskfile to run. Defaults to "Taskfile.yml".`) |
| 147 | pflag.StringVar(&TempDir, "temp-dir", getConfig(config, "TEMP_DIR", func() *string { return config.TempDir }, ""), "Sets the directory used to store Task temporary files, such as checksums. Relative paths are relative to the root Taskfile.") |
| 148 | pflag.StringVarP(&Output.Name, "output", "o", getConfig(config, "OUTPUT", func() *string { return nil }, ""), "Sets output style: [interleaved|group|prefixed].") |
| 149 | pflag.StringVar(&Output.Group.Begin, "output-group-begin", getConfig(config, "OUTPUT_GROUP_BEGIN", func() *string { return nil }, ""), "Message template to print before a task's grouped output.") |
| 150 | pflag.StringVar(&Output.Group.End, "output-group-end", getConfig(config, "OUTPUT_GROUP_END", func() *string { return nil }, ""), "Message template to print after a task's grouped output.") |
nothing calls this directly
no test coverage detected
searching dependent graphs…