From 1b4cc572f71f92f9ca0d3df389441d94ada06732 Mon Sep 17 00:00:00 2001 From: Jens Feodor Nielsen Date: Tue, 10 Dec 2024 09:30:55 +0100 Subject: [PATCH] app list: use configured organization and fix organization flag usage text --- cmd/app/list/cmd.go | 16 ++++++++++++---- cmd/args/appident.go | 6 +----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cmd/app/list/cmd.go b/cmd/app/list/cmd.go index 1f3b4b1..437539f 100644 --- a/cmd/app/list/cmd.go +++ b/cmd/app/list/cmd.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/spf13/cobra" - "numerous.com/cli/cmd/args" "numerous.com/cli/cmd/errorhandling" "numerous.com/cli/cmd/output" "numerous.com/cli/internal/app" + "numerous.com/cli/internal/config" "numerous.com/cli/internal/gql" ) @@ -20,8 +20,16 @@ var Cmd = &cobra.Command{ } func run(cmd *cobra.Command) error { - if cmdArgs.organizationSlug == "" { - output.PrintError("Missing organization argument.", "") + orgSlug := cmdArgs.organizationSlug + if orgSlug == "" { + orgSlug = config.OrganizationSlug() + } + + if orgSlug == "" { + output.PrintError( + "No organization provided or configured", + "Specify an organization with the --organization flag, or configure one with \"numerous config\".", + ) cmd.Usage() // nolint:errcheck return errorhandling.ErrAlreadyPrinted @@ -35,5 +43,5 @@ func run(cmd *cobra.Command) error { func init() { flags := Cmd.Flags() - args.AddOrganizationSlugFlag(flags, "to list apps from", &cmdArgs.organizationSlug) + flags.StringVarP(&cmdArgs.organizationSlug, "organization", "o", "", "The organization slug identifier to list apps from. List available organizations with 'numerous organization list'.") } diff --git a/cmd/args/appident.go b/cmd/args/appident.go index 3d5e64b..2a0ce96 100644 --- a/cmd/args/appident.go +++ b/cmd/args/appident.go @@ -10,10 +10,6 @@ type AppIdentifierArg struct { } func (a *AppIdentifierArg) AddAppIdentifierFlags(flags *pflag.FlagSet, action string) { - AddOrganizationSlugFlag(flags, action, &a.OrganizationSlug) + flags.StringVarP(&a.OrganizationSlug, "organization", "o", "", "The organization slug identifier of the app "+action+". List available organizations with 'numerous organization list'.") flags.StringVarP(&a.AppSlug, "app", "a", "", "An app slug identifier of the app "+action+".") } - -func AddOrganizationSlugFlag(flags *pflag.FlagSet, action string, orgSlug *string) { - flags.StringVarP(orgSlug, "organization", "o", "", "The organization slug identifier of the app "+action+". List available organizations with 'numerous organization list'.") -}