diff --git a/cmd/close.go b/cmd/close.go index c4107775..ab2b38d4 100644 --- a/cmd/close.go +++ b/cmd/close.go @@ -20,7 +20,7 @@ func CloseCmd() *cobra.Command { cmd.Flags().StringP("branch", "B", "multi-gitter-branch", "The name of the branch where changes are committed.") configurePlatform(cmd) - cmd.Flags().AddFlagSet(logFlags("-")) + configureLogging(cmd, "-") return cmd } diff --git a/cmd/merge.go b/cmd/merge.go index bae535f5..1fd7edd5 100644 --- a/cmd/merge.go +++ b/cmd/merge.go @@ -21,7 +21,7 @@ func MergeCmd() *cobra.Command { cmd.Flags().StringP("branch", "B", "multi-gitter-branch", "The name of the branch where changes are committed.") cmd.Flags().StringSliceP("merge-type", "", []string{"merge", "squash", "rebase"}, "The type of merge that should be done (GitHub). Multiple types can be used as backup strategies if the first one is not allowed.") configurePlatform(cmd) - cmd.Flags().AddFlagSet(logFlags("-")) + configureLogging(cmd, "-") return cmd } diff --git a/cmd/print.go b/cmd/print.go index 4d3715cd..63ea266d 100755 --- a/cmd/print.go +++ b/cmd/print.go @@ -36,7 +36,7 @@ func PrintCmd() *cobra.Command { cmd.Flags().IntP("fetch-depth", "f", 1, "Limit fetching to the specified number of commits. Set to 0 for no limit") cmd.Flags().StringP("error-output", "E", "-", `The file that the output of the script should be outputted to. "-" means stderr`) configurePlatform(cmd) - cmd.Flags().AddFlagSet(logFlags("")) + configureLogging(cmd, "") cmd.Flags().AddFlagSet(outputFlag()) return cmd diff --git a/cmd/root.go b/cmd/root.go index ce1de2d1..06e2983e 100755 --- a/cmd/root.go +++ b/cmd/root.go @@ -55,6 +55,9 @@ func configurePlatform(cmd *cobra.Command) { flags.StringSliceP("project", "P", nil, "The name, including owner of a GitLab project in the format \"ownerName/repoName\"") flags.StringP("platform", "p", "github", "The platform that is used. Available values: github, gitlab") + _ = cmd.RegisterFlagCompletionFunc("platform", func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { + return []string{"github", "gitlab"}, cobra.ShellCompDirectiveDefault + }) // Autocompletion for organizations _ = cmd.RegisterFlagCompletionFunc("org", func(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) { @@ -129,14 +132,20 @@ func configurePlatform(cmd *cobra.Command) { }) } -func logFlags(logFile string) *flag.FlagSet { - flags := flag.NewFlagSet("log", flag.ExitOnError) +func configureLogging(cmd *cobra.Command, logFile string) { + flags := cmd.Flags() flags.StringP("log-level", "L", "info", "The level of logging that should be made. Available values: trace, debug, info, error") + _ = cmd.RegisterFlagCompletionFunc("log-level", func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { + return []string{"trace", "debug", "info", "error"}, cobra.ShellCompDirectiveDefault + }) + flags.StringP("log-format", "", "text", `The formating of the logs. Available values: text, json, json-pretty`) - flags.StringP("log-file", "", logFile, `The file where all logs should be printed to. "-" means stdout`) + _ = cmd.RegisterFlagCompletionFunc("log-format", func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { + return []string{"text", "json", "json-pretty"}, cobra.ShellCompDirectiveDefault + }) - return flags + flags.StringP("log-file", "", logFile, `The file where all logs should be printed to. "-" means stdout`) } func logFlagInit(cmd *cobra.Command, args []string) error { diff --git a/cmd/run.go b/cmd/run.go index a8afeea4..e2e6eaf9 100755 --- a/cmd/run.go +++ b/cmd/run.go @@ -48,7 +48,7 @@ func RunCmd() *cobra.Command { cmd.Flags().StringP("author-name", "", "", "Name of the committer. If not set, the global git config setting will be used.") cmd.Flags().StringP("author-email", "", "", "Email of the committer. If not set, the global git config setting will be used.") configurePlatform(cmd) - cmd.Flags().AddFlagSet(logFlags("-")) + configureLogging(cmd, "-") cmd.Flags().AddFlagSet(outputFlag()) return cmd diff --git a/cmd/status.go b/cmd/status.go index 281a3f2c..4b8914d6 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -21,7 +21,7 @@ func StatusCmd() *cobra.Command { cmd.Flags().StringP("branch", "B", "multi-gitter-branch", "The name of the branch where changes are committed.") configurePlatform(cmd) - cmd.Flags().AddFlagSet(logFlags("-")) + configureLogging(cmd, "-") cmd.Flags().AddFlagSet(outputFlag()) return cmd diff --git a/go.sum b/go.sum index c22c8387..1e8783f5 100644 --- a/go.sum +++ b/go.sum @@ -77,6 +77,7 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=