Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func init() {
"account",
"c",
"",
"AWS account ID or alias (not needed if you are only the administrator of one account)",
"AWS account ID or alias. Use this flag to override the APPPACK_ACCOUNT environment variable (not needed if you are the administrator of only one account).",
)
accessCmd.PersistentFlags().BoolVar(
&UseAWSCredentials,
Expand Down
2 changes: 1 addition & 1 deletion cmd/admins.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func init() {
"account",
"c",
"",
"AWS account ID or alias (not needed if you are only the administrator of one account)",
"AWS account ID or alias. Use this flag to override the APPPACK_ACCOUNT environment variable (not needed if you are the administrator of only one account).",
)
adminsCmd.PersistentFlags().BoolVar(
&UseAWSCredentials,
Expand Down
2 changes: 1 addition & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ var createRegionCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(createCmd)
createCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias (not needed if you are only the administrator of one account)")
createCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias. Use this flag to override the APPPACK_ACCOUNT environment variable (not needed if you are the administrator of only one account).")
createCmd.PersistentFlags().BoolVar(&UseAWSCredentials, "aws-credentials", false, "use AWS credentials instead of AppPack.io federation")
createCmd.PersistentFlags().BoolVar(&createChangeSet, "check", false, "check stack in Cloudformation before creating")
createCmd.PersistentFlags().BoolVar(&nonInteractive, "non-interactive", false, "do not prompt for missing flags")
Expand Down
2 changes: 1 addition & 1 deletion cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ var destroyCustomDomainCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(destroyCmd)
destroyCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias (not needed if you are only the administrator of one account)")
destroyCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias. Use this flag to override the APPPACK_ACCOUNT environment variable (not needed if you are the administrator of only one account).")
destroyCmd.PersistentFlags().BoolVar(&UseAWSCredentials, "aws-credentials", false, "use AWS credentials instead of AppPack.io federation")
destroyCmd.PersistentFlags().StringVar(&region, "region", "", "AWS region to destroy resources in")

Expand Down
2 changes: 1 addition & 1 deletion cmd/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ package cmd

// func init() {
// rootCmd.AddCommand(modifyCmd)
// modifyCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias (not needed if you are only the administrator of one account)")
// modifyCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias. Use this flag to override the APPPACK_ACCOUNT environment variable (not needed if you are the administrator of only one account).")
// modifyCmd.PersistentFlags().BoolVar(&UseAWSCredentials, "aws-credentials", false, "use AWS credentials instead of AppPack.io federation")
// modifyCmd.PersistentFlags().BoolVar(&createChangeSet, "check", false, "check stack in Cloudformation before creating")
// modifyCmd.PersistentFlags().BoolVar(&nonInteractive, "non-interactive", false, "do not prompt for user input")
Expand Down
17 changes: 17 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ var (
MaxSessionDurationSeconds = 3600
)

func userHasMultipleAccounts() bool {
ui.StartSpinner()
admins, err := auth.AdminList()
checkErr(err)
ui.Spinner.Stop()
return len(admins) > 1
}

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "apppack",
Expand All @@ -64,6 +72,15 @@ var rootCmd = &cobra.Command{
} else {
logrus.SetLevel(logrus.ErrorLevel)
}
// Check for account flag or environment variable
if AccountIDorAlias == "" {
AccountIDorAlias = os.Getenv("APPPACK_ACCOUNT")
}

// If neither is set and the user has multiple accounts, throw an error
if AccountIDorAlias == "" && userHasMultipleAccounts() {
checkErr(fmt.Errorf("you must specify an account using the -c flag or the APPPACK_ACCOUNT environment variable"))
}
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ var stacksCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(stacksCmd)
stacksCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias (not needed if you are only the administrator of one account)")
stacksCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias. Use this flag to override the APPPACK_ACCOUNT environment variable (not needed if you are the administrator of only one account).")
stacksCmd.PersistentFlags().BoolVar(&UseAWSCredentials, "aws-credentials", false, "use AWS credentials instead of AppPack.io federation")
}
2 changes: 1 addition & 1 deletion cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ var upgradeDatabaseCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(upgradeCmd)
upgradeCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias (not needed if you are only the administrator of one account)")
upgradeCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias. Use this flag to override the APPPACK_ACCOUNT environment variable (not needed if you are the administrator of only one account).")
upgradeCmd.PersistentFlags().BoolVar(&UseAWSCredentials, "aws-credentials", false, "use AWS credentials instead of AppPack.io federation")
upgradeCmd.PersistentFlags().BoolVar(&createChangeSet, "check", false, "check stack in Cloudformation before creating")
upgradeCmd.PersistentFlags().StringVar(&region, "region", "", "AWS region to upgrade resources in")
Expand Down