-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switched to cobra for the cli parsing, added saving to a dotenv (…
…#11)
- Loading branch information
1 parent
ec2aa75
commit ede245b
Showing
16 changed files
with
235 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/jeff-roche/biome/src/services" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var biomeService *services.BiomeConfigurationService | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "biome", | ||
Short: "An environment configuration tool", | ||
Long: `An environment variable configuration tool with capabilities such as: | ||
- CLI input | ||
- Configuration commands | ||
- AWS environment configuration | ||
- AWS Secrets Manager support | ||
- Environment variable decryption`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
// Run: func(cmd *cobra.Command, args []string) { }, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute(biomeSvc *services.BiomeConfigurationService) { | ||
biomeService = biomeSvc | ||
|
||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
// Here you will define your flags and configuration settings. | ||
// Cobra supports persistent flags, which, if defined here, | ||
// will be global for your application. | ||
|
||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
//rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/jeff-roche/biome/src/lib/cmdr" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// runCmd represents the run command | ||
var runCmd = &cobra.Command{ | ||
Use: "run -b <biome-name> [flags] [...cmd]", | ||
Short: "Run any cli command in the provided biome", | ||
Long: "Run any cli command in the provided biome", | ||
Args: cobra.MinimumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
biomeName, _ := cmd.Flags().GetString("biome") | ||
|
||
if err := biomeService.LoadBiomeFromDefaults(biomeName); err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
if err := biomeService.ActivateBiome(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
// Execute order 66 | ||
if err := cmdr.Run(args[0], args[1:]...); err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(runCmd) | ||
|
||
runCmd.Flags().StringP("biome", "b", "", "the name of the biome to configure") | ||
runCmd.MarkFlagRequired("biome") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// saveCmd represents the save command | ||
var saveCmd = &cobra.Command{ | ||
Use: "save", | ||
Short: "Save the loaded environment variables to a dotenv (.env) file", | ||
Long: `Save the loaded environment variables to a dotenv (.env) file | ||
The default file is '.env' in the current directory`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
biomeName, _ := cmd.Flags().GetString("biome") | ||
fileName, _ := cmd.Flags().GetString("file") | ||
fmt.Println("LLAMA") | ||
fmt.Println(biomeName) | ||
|
||
if err := biomeService.LoadBiomeFromDefaults(biomeName); err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
if err := biomeService.ActivateBiome(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
// Execute order 66 | ||
if err := biomeService.SaveBiomeToFile(fileName); err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(saveCmd) | ||
|
||
saveCmd.Flags().StringP("file", "f", ".env", "set the output file name") | ||
saveCmd.Flags().StringP("biome", "b", "", "the name of the biome to configure") | ||
saveCmd.MarkFlagRequired("biome") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.