commands

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Generate = &cli.Command{
	Name:  "generate",
	Usage: "Generate AWS config",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:     "ssoURL",
			Aliases:  []string{"s"},
			Usage:    "AWS Single Sign On URL",
			Required: true,
		},
		&cli.StringFlag{
			Name:    "region",
			Aliases: []string{"r"},
			Usage:   "AWS Region used by SSO",
		},
	},
	Action: func(c *cli.Context) error {
		ssoURL := c.String("ssoURL")
		region := c.String("region")

		if c.String("region") == "" {
			region = "us-east-1"
		}

		configDir := configDirName()
		configFile := filepath.Join(configDir, "config")

		if !fileExists(configFile) {

			createPath(configDir)
			generateConfig(ssoURL, region)
		} else {
			// config already exists, check if the user wants to overwrite
			var selectedOption string
			fmt.Print("Overwrite current config(~/.aws/config)[y/N]? ")
			_, err := fmt.Scanf("%s", &selectedOption)
			if err != nil {
				fmt.Println("Default option")
			}

			if selectedOption == "y" || selectedOption == "Y" {
				generateConfig(ssoURL, region)
			} else {
				printConfig(ssoURL, region)
			}
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL