mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-31 01:53:50 +02:00
feat: completion improvements (#4071)
See individual commits for details.
This commit is contained in:
parent
703578a767
commit
1c9b4d56b4
23
cmd/build.go
23
cmd/build.go
@ -58,9 +58,10 @@ It also allows you to generate a local build for your current machine only using
|
||||
|
||||
When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`" + ` environment variables are used to determine the target, defaulting to the current machine target if not set.
|
||||
`,
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
RunE: timedRunE("build", func(cmd *cobra.Command, args []string) error {
|
||||
ctx, err := buildProject(root.opts)
|
||||
if err != nil {
|
||||
@ -72,6 +73,7 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&root.opts.config, "config", "f", "", "Load configuration from file")
|
||||
_ = cmd.MarkFlagFilename("config", "yaml", "yml")
|
||||
cmd.Flags().BoolVar(&root.opts.snapshot, "snapshot", false, "Generate an unversioned snapshot build, skipping all validations")
|
||||
cmd.Flags().BoolVar(&root.opts.skipValidate, "skip-validate", false, "Skips several sanity checks")
|
||||
cmd.Flags().BoolVar(&root.opts.skipBefore, "skip-before", false, "Skips global before hooks")
|
||||
@ -79,12 +81,25 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
|
||||
cmd.Flags().BoolVar(&root.opts.clean, "clean", false, "Remove the dist folder before building")
|
||||
cmd.Flags().BoolVar(&root.opts.rmDist, "rm-dist", false, "Remove the dist folder before building")
|
||||
cmd.Flags().IntVarP(&root.opts.parallelism, "parallelism", "p", 0, "Amount tasks to run concurrently (default: number of CPUs)")
|
||||
_ = cmd.RegisterFlagCompletionFunc("parallelism", cobra.NoFileCompletions)
|
||||
cmd.Flags().DurationVar(&root.opts.timeout, "timeout", 30*time.Minute, "Timeout to the entire build process")
|
||||
_ = cmd.RegisterFlagCompletionFunc("timeout", cobra.NoFileCompletions)
|
||||
cmd.Flags().BoolVar(&root.opts.singleTarget, "single-target", false, "Builds only for current GOOS and GOARCH, regardless of what's set in the configuration file")
|
||||
cmd.Flags().StringArrayVar(&root.opts.ids, "id", nil, "Builds only the specified build ids")
|
||||
_ = cmd.RegisterFlagCompletionFunc("id", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
cfg, err := loadConfig(root.opts.config)
|
||||
if err != nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
ids := make([]string, 0, len(cfg.Builds))
|
||||
for _, build := range cfg.Builds {
|
||||
ids = append(ids, build.ID)
|
||||
}
|
||||
return ids, cobra.ShellCompDirectiveNoFileComp
|
||||
})
|
||||
cmd.Flags().BoolVar(&root.opts.deprecated, "deprecated", false, "Force print the deprecation message - tests only")
|
||||
cmd.Flags().StringVarP(&root.opts.output, "output", "o", "", "Copy the binary to the path after the build. Only taken into account when using --single-target and a single id (either with --id or if configuration only has one build)")
|
||||
_ = cmd.Flags().SetAnnotation("output", cobra.BashCompFilenameExt, []string{""})
|
||||
_ = cmd.MarkFlagFilename("output", "")
|
||||
_ = cmd.Flags().MarkHidden("rm-dist")
|
||||
_ = cmd.Flags().MarkHidden("deprecated")
|
||||
|
||||
|
@ -91,6 +91,7 @@ func newCheckCmd() *checkCmd {
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&root.config, "config", "f", "", "Configuration file(s) to check")
|
||||
_ = cmd.MarkFlagFilename("config", "yaml", "yml")
|
||||
cmd.Flags().BoolVarP(&root.quiet, "quiet", "q", false, "Quiet mode: no output")
|
||||
cmd.Flags().BoolVar(&root.deprecated, "deprecated", false, "Force print the deprecation message - tests only")
|
||||
_ = cmd.Flags().MarkHidden("deprecated")
|
||||
|
@ -20,6 +20,7 @@ func newDocsCmd() *docsCmd {
|
||||
DisableFlagsInUseLine: true,
|
||||
Hidden: true,
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
root.cmd.Root().DisableAutoGenTag = true
|
||||
return doc.GenMarkdownTreeCustom(root.cmd.Root(), "www/docs/cmd", func(_ string) string {
|
||||
|
@ -25,13 +25,14 @@ type healthcheckCmd struct {
|
||||
func newHealthcheckCmd() *healthcheckCmd {
|
||||
root := &healthcheckCmd{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "healthcheck",
|
||||
Aliases: []string{"hc"},
|
||||
Short: "Checks if needed tools are installed",
|
||||
Long: `Check if the needed tools are available in your $PATH, exits 1 if any of them are missing.`,
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
Use: "healthcheck",
|
||||
Aliases: []string{"hc"},
|
||||
Short: "Checks if needed tools are installed",
|
||||
Long: `Check if the needed tools are available in your $PATH, exits 1 if any of them are missing.`,
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if root.quiet {
|
||||
log.Log = log.New(io.Discard)
|
||||
@ -81,6 +82,7 @@ func newHealthcheckCmd() *healthcheckCmd {
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&root.config, "config", "f", "", "Configuration file")
|
||||
_ = cmd.MarkFlagFilename("config", "yaml", "yml")
|
||||
cmd.Flags().BoolVarP(&root.quiet, "quiet", "q", false, "Quiet mode: no output")
|
||||
_ = cmd.Flags().MarkHidden("deprecated")
|
||||
|
||||
|
14
cmd/init.go
14
cmd/init.go
@ -17,12 +17,13 @@ type initCmd struct {
|
||||
func newInitCmd() *initCmd {
|
||||
root := &initCmd{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Aliases: []string{"i"},
|
||||
Short: "Generates a .goreleaser.yaml file",
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
Use: "init",
|
||||
Aliases: []string{"i"},
|
||||
Short: "Generates a .goreleaser.yaml file",
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
conf, err := os.OpenFile(root.config, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_EXCL, 0o644)
|
||||
if err != nil {
|
||||
@ -50,6 +51,7 @@ func newInitCmd() *initCmd {
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&root.config, "config", "f", ".goreleaser.yaml", "Load configuration from file")
|
||||
_ = cmd.MarkFlagFilename("config", "yaml", "yml")
|
||||
|
||||
root.cmd = cmd
|
||||
return root
|
||||
|
@ -22,6 +22,7 @@ func newManCmd() *manCmd {
|
||||
DisableFlagsInUseLine: true,
|
||||
Hidden: true,
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
manPage, err := mcoral.NewManPage(1, root.cmd.Root())
|
||||
if err != nil {
|
||||
|
@ -50,12 +50,13 @@ func newReleaseCmd() *releaseCmd {
|
||||
root := &releaseCmd{}
|
||||
// nolint: dupl
|
||||
cmd := &cobra.Command{
|
||||
Use: "release",
|
||||
Aliases: []string{"r"},
|
||||
Short: "Releases the current project",
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
Use: "release",
|
||||
Aliases: []string{"r"},
|
||||
Short: "Releases the current project",
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
RunE: timedRunE("release", func(cmd *cobra.Command, args []string) error {
|
||||
ctx, err := releaseProject(root.opts)
|
||||
if err != nil {
|
||||
@ -67,12 +68,19 @@ func newReleaseCmd() *releaseCmd {
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&root.opts.config, "config", "f", "", "Load configuration from file")
|
||||
_ = cmd.MarkFlagFilename("config", "yaml", "yml")
|
||||
cmd.Flags().StringVar(&root.opts.releaseNotesFile, "release-notes", "", "Load custom release notes from a markdown file (will skip GoReleaser changelog generation)")
|
||||
_ = cmd.MarkFlagFilename("release-notes", "md", "mkd", "markdown")
|
||||
cmd.Flags().StringVar(&root.opts.releaseHeaderFile, "release-header", "", "Load custom release notes header from a markdown file")
|
||||
_ = cmd.MarkFlagFilename("release-header", "md", "mkd", "markdown")
|
||||
cmd.Flags().StringVar(&root.opts.releaseFooterFile, "release-footer", "", "Load custom release notes footer from a markdown file")
|
||||
_ = cmd.MarkFlagFilename("release-footer", "md", "mkd", "markdown")
|
||||
cmd.Flags().StringVar(&root.opts.releaseNotesTmpl, "release-notes-tmpl", "", "Load custom release notes from a templated markdown file (overrides --release-notes)")
|
||||
_ = cmd.MarkFlagFilename("release-notes-tmpl", "md", "mkd", "markdown")
|
||||
cmd.Flags().StringVar(&root.opts.releaseHeaderTmpl, "release-header-tmpl", "", "Load custom release notes header from a templated markdown file (overrides --release-header)")
|
||||
_ = cmd.MarkFlagFilename("release-header-tmpl", "md", "mkd", "markdown")
|
||||
cmd.Flags().StringVar(&root.opts.releaseFooterTmpl, "release-footer-tmpl", "", "Load custom release notes footer from a templated markdown file (overrides --release-footer)")
|
||||
_ = cmd.MarkFlagFilename("release-footer-tmpl", "md", "mkd", "markdown")
|
||||
cmd.Flags().BoolVar(&root.opts.autoSnapshot, "auto-snapshot", false, "Automatically sets --snapshot if the repository is dirty")
|
||||
cmd.Flags().BoolVar(&root.opts.snapshot, "snapshot", false, "Generate an unversioned snapshot release, skipping all validations and without publishing any artifacts (implies --skip-publish, --skip-announce and --skip-validate)")
|
||||
cmd.Flags().BoolVar(&root.opts.skipPublish, "skip-publish", false, "Skips publishing artifacts (implies --skip-announce)")
|
||||
@ -86,12 +94,13 @@ func newReleaseCmd() *releaseCmd {
|
||||
cmd.Flags().BoolVar(&root.opts.clean, "clean", false, "Removes the dist folder")
|
||||
cmd.Flags().BoolVar(&root.opts.rmDist, "rm-dist", false, "Removes the dist folder")
|
||||
cmd.Flags().IntVarP(&root.opts.parallelism, "parallelism", "p", 0, "Amount tasks to run concurrently (default: number of CPUs)")
|
||||
_ = cmd.RegisterFlagCompletionFunc("parallelism", cobra.NoFileCompletions)
|
||||
cmd.Flags().DurationVar(&root.opts.timeout, "timeout", 30*time.Minute, "Timeout to the entire release process")
|
||||
_ = cmd.RegisterFlagCompletionFunc("timeout", cobra.NoFileCompletions)
|
||||
cmd.Flags().BoolVar(&root.opts.deprecated, "deprecated", false, "Force print the deprecation message - tests only")
|
||||
_ = cmd.Flags().MarkHidden("deprecated")
|
||||
_ = cmd.Flags().MarkHidden("rm-dist")
|
||||
_ = cmd.Flags().MarkDeprecated("rm-dist", "please use --clean instead")
|
||||
_ = cmd.Flags().SetAnnotation("config", cobra.BashCompFilenameExt, []string{"yaml", "yml"})
|
||||
|
||||
root.cmd = cmd
|
||||
return root
|
||||
|
@ -67,10 +67,11 @@ You can customize your entire release process through a single .goreleaser.yaml
|
||||
|
||||
Check out our website for more information, examples and documentation: https://goreleaser.com
|
||||
`,
|
||||
Version: version.String(),
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
Version: version.String(),
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
PersistentPreRun: func(_ *cobra.Command, _ []string) {
|
||||
if root.verbose || root.debug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
@ -19,12 +19,13 @@ type schemaCmd struct {
|
||||
func newSchemaCmd() *schemaCmd {
|
||||
root := &schemaCmd{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "jsonschema",
|
||||
Aliases: []string{"schema"},
|
||||
Short: "outputs goreleaser's JSON schema",
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
Use: "jsonschema",
|
||||
Aliases: []string{"schema"},
|
||||
Short: "outputs goreleaser's JSON schema",
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
schema := jsonschema.Reflect(&config.Project{})
|
||||
schema.Definitions["FileInfo"] = jsonschema.Reflect(&config.FileInfo{})
|
||||
@ -48,7 +49,7 @@ func newSchemaCmd() *schemaCmd {
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&root.output, "output", "o", "-", "Where to save the JSONSchema file")
|
||||
_ = cmd.Flags().SetAnnotation("output", cobra.BashCompFilenameExt, []string{"json"})
|
||||
_ = cmd.MarkFlagFilename("output", "json")
|
||||
|
||||
root.cmd = cmd
|
||||
return root
|
||||
|
Loading…
Reference in New Issue
Block a user