Skip to content

Commit 2e93e2a

Browse files
committed
feat(general): lots of changes have been made
1 parent cbb5321 commit 2e93e2a

22 files changed

+643
-83
lines changed

cmd/docs.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright © 2022 James Ray [email protected]
3+
4+
*/
5+
package cmd
6+
7+
import (
8+
"log"
9+
10+
"github.com/spf13/cobra"
11+
"github.com/spf13/cobra/doc"
12+
)
13+
14+
// docsCmd represents the docs command
15+
var docsCmd = &cobra.Command{
16+
Use: "docs",
17+
Short: "Auto Generates MarkDown documentation",
18+
Run: func(cmd *cobra.Command, args []string) {
19+
err := doc.GenMarkdownTree(rootCmd, "./docs")
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
},
24+
}
25+
26+
func init() {
27+
rootCmd.AddCommand(docsCmd)
28+
29+
// Here you will define your flags and configuration settings.
30+
31+
// Cobra supports Persistent Flags which will work for this command
32+
// and all subcommands, e.g.:
33+
// docsCmd.PersistentFlags().String("foo", "", "A help for foo")
34+
35+
// Cobra supports local flags which will only run when this command
36+
// is called directly, e.g.:
37+
// docsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
38+
}

cmd/init.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,28 @@ Copyright © 2022 James Ray [email protected]
55
package cmd
66

77
import (
8-
"log"
9-
"os"
10-
"path/filepath"
11-
8+
"github.com/rayprogramming/toolsium/lib/config"
129
"github.com/spf13/cobra"
13-
"github.com/spf13/viper"
1410
)
1511

1612
// initCmd represents the init command
1713
var initCmd = &cobra.Command{
1814
Use: "init",
1915
Short: "Setup toolsium",
2016
Run: func(cmd *cobra.Command, args []string) {
21-
home, err := os.UserHomeDir()
17+
err := config.CreateConfig()
2218
cobra.CheckErr(err)
23-
if err := viper.WriteConfigAs(filepath.Join(home, cfgFileName)); err != nil {
24-
log.Fatal(err)
25-
}
2619
},
2720
}
2821

2922
func init() {
3023
rootCmd.AddCommand(initCmd)
3124

3225
initCmd.Flags().StringP("mfa_serial", "m", "", "The MFA serial for your account")
33-
viper.BindPFlag("mfa_serial", initCmd.Flags().Lookup("mfa_serial"))
34-
viper.SetDefault("mfa_serial", "")
26+
config.GetViper().BindPFlag("mfa_serial", initCmd.Flags().Lookup("mfa_serial"))
27+
config.GetViper().SetDefault("mfa_serial", "")
3528

3629
initCmd.Flags().StringP("department", "d", "", "Department filter")
37-
viper.BindPFlag("department", initCmd.Flags().Lookup("department"))
38-
viper.SetDefault("department", "")
30+
config.GetViper().BindPFlag("department", initCmd.Flags().Lookup("department"))
31+
config.GetViper().SetDefault("department", "")
3932
}

cmd/papi.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,4 @@ to quickly create a Cobra application.`,
6161

6262
func init() {
6363
manageCmd.AddCommand(papiCmd)
64-
65-
// Here you will define your flags and configuration settings.
66-
67-
// Cobra supports Persistent Flags which will work for this command
68-
// and all subcommands, e.g.:
69-
// papiCmd.PersistentFlags().String("foo", "", "A help for foo")
70-
71-
// Cobra supports local flags which will only run when this command
72-
// is called directly, e.g.:
73-
// papiCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
7464
}

cmd/root.go

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ import (
88
"fmt"
99
"os"
1010

11+
"github.com/rayprogramming/toolsium/lib/config"
1112
"github.com/spf13/cobra"
12-
"github.com/spf13/viper"
13-
)
14-
15-
const (
16-
cfgFileName = ".toolsium"
17-
cfgFileType = "json"
1813
)
1914

2015
var (
@@ -24,33 +19,11 @@ var (
2419
// rootCmd represents the base command when called without any subcommands
2520
var rootCmd = &cobra.Command{
2621
Use: "toolsium",
27-
Short: "A brief description of your application",
28-
Long: `A longer description that spans multiple lines and likely contains
29-
examples and usage of using your application. For example:
30-
31-
Cobra is a CLI library for Go that empowers applications.
32-
This application is a tool to generate the needed files
33-
to quickly create a Cobra application.`,
34-
// Uncomment the following line if your bare application
35-
// has an action associated with it:
36-
// Run: func(cmd *cobra.Command, args []string) {
37-
// cfg, err := config.LoadDefaultConfig(context.TODO())
38-
// cfg.Credentials = aws.NewCredentialsCache(&lib.MfaProvider{})
39-
40-
// if err != nil {
41-
// log.Fatal(err)
42-
// }
43-
44-
// client := s3.NewFromConfig(cfg)
45-
// output, err := client.ListBuckets(context.TODO(), &s3.ListBucketsInput{})
46-
// if err != nil {
47-
// log.Fatal(err)
48-
// }
49-
50-
// for _, object := range output.Buckets {
51-
// log.Printf("Bucket=%s", aws.ToString(object.Name))
52-
// }
53-
// },
22+
Short: "A handy set of tools for developers",
23+
Long: `Toolsium is desgined to allow developers to quickly access common resources they would be expected to use.
24+
25+
These tools can include default filters, easy access to start a session on an ec2 machine, and other features.
26+
`,
5427
}
5528

5629
// Execute adds all child commands to the root command and sets flags appropriately.
@@ -64,31 +37,15 @@ func Execute() {
6437

6538
func init() {
6639
cobra.OnInitialize(initConfig)
67-
68-
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", fmt.Sprintf("config file (default is $HOME/%v.%v)", cfgFileName, cfgFileType))
40+
confDir, err := config.GetConfigDir()
41+
cobra.CheckErr(err)
42+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", fmt.Sprintf("config file (default is %v)", confDir))
6943
// Instead of profiles for now, I recommend just passing in different config files.
44+
7045
}
7146

7247
// initConfig reads in config file and ENV variables if set.
7348
func initConfig() {
74-
if cfgFile != "" {
75-
// Use config file from the flag.
76-
viper.SetConfigFile(cfgFile)
77-
} else {
78-
// Find home directory.
79-
home, err := os.UserHomeDir()
80-
cobra.CheckErr(err)
81-
82-
// Search config in home directory with name ".toolsium" (without extension).
83-
viper.AddConfigPath(home)
84-
viper.SetConfigType(cfgFileType)
85-
viper.SetConfigName(cfgFileName)
86-
}
87-
88-
viper.AutomaticEnv() // read in environment variables that match
89-
90-
// If a config file is found, read it in.
91-
if err := viper.ReadInConfig(); err == nil {
92-
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
93-
}
49+
err := config.Configure(cfgFile)
50+
cobra.CheckErr(err)
9451
}

docs/toolsium.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## toolsium
2+
3+
A handy set of tools for developers
4+
5+
### Synopsis
6+
7+
Toolsium is desgined to allow developers to quickly access common resources they would be expected to use.
8+
9+
These tools can include default filters, easy access to start a session on an ec2 machine, and other features.
10+
11+
12+
### Options
13+
14+
```
15+
--config string config file (default is $HOME/.toolsium.json)
16+
-h, --help help for toolsium
17+
```
18+
19+
### SEE ALSO
20+
21+
* [toolsium completion](toolsium_completion.md) - Generate the autocompletion script for the specified shell
22+
* [toolsium docs](toolsium_docs.md) - Auto Generates MarkDown documentation
23+
* [toolsium init](toolsium_init.md) - Setup toolsium
24+
* [toolsium manage](toolsium_manage.md) - A brief description of your command
25+
* [toolsium mfa](toolsium_mfa.md) - A brief description of your command
26+
27+
###### Auto generated by spf13/cobra on 27-Aug-2022

docs/toolsium_completion.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## toolsium completion
2+
3+
Generate the autocompletion script for the specified shell
4+
5+
### Synopsis
6+
7+
Generate the autocompletion script for toolsium for the specified shell.
8+
See each sub-command's help for details on how to use the generated script.
9+
10+
11+
### Options
12+
13+
```
14+
-h, --help help for completion
15+
```
16+
17+
### Options inherited from parent commands
18+
19+
```
20+
--config string config file (default is $HOME/.toolsium.json)
21+
```
22+
23+
### SEE ALSO
24+
25+
* [toolsium](toolsium.md) - A handy set of tools for developers
26+
* [toolsium completion bash](toolsium_completion_bash.md) - Generate the autocompletion script for bash
27+
* [toolsium completion fish](toolsium_completion_fish.md) - Generate the autocompletion script for fish
28+
* [toolsium completion powershell](toolsium_completion_powershell.md) - Generate the autocompletion script for powershell
29+
* [toolsium completion zsh](toolsium_completion_zsh.md) - Generate the autocompletion script for zsh
30+
31+
###### Auto generated by spf13/cobra on 27-Aug-2022

docs/toolsium_completion_bash.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## toolsium completion bash
2+
3+
Generate the autocompletion script for bash
4+
5+
### Synopsis
6+
7+
Generate the autocompletion script for the bash shell.
8+
9+
This script depends on the 'bash-completion' package.
10+
If it is not installed already, you can install it via your OS's package manager.
11+
12+
To load completions in your current shell session:
13+
14+
source <(toolsium completion bash)
15+
16+
To load completions for every new session, execute once:
17+
18+
#### Linux:
19+
20+
toolsium completion bash > /etc/bash_completion.d/toolsium
21+
22+
#### macOS:
23+
24+
toolsium completion bash > $(brew --prefix)/etc/bash_completion.d/toolsium
25+
26+
You will need to start a new shell for this setup to take effect.
27+
28+
29+
```
30+
toolsium completion bash
31+
```
32+
33+
### Options
34+
35+
```
36+
-h, --help help for bash
37+
--no-descriptions disable completion descriptions
38+
```
39+
40+
### Options inherited from parent commands
41+
42+
```
43+
--config string config file (default is $HOME/.toolsium.json)
44+
```
45+
46+
### SEE ALSO
47+
48+
* [toolsium completion](toolsium_completion.md) - Generate the autocompletion script for the specified shell
49+
50+
###### Auto generated by spf13/cobra on 27-Aug-2022

docs/toolsium_completion_fish.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## toolsium completion fish
2+
3+
Generate the autocompletion script for fish
4+
5+
### Synopsis
6+
7+
Generate the autocompletion script for the fish shell.
8+
9+
To load completions in your current shell session:
10+
11+
toolsium completion fish | source
12+
13+
To load completions for every new session, execute once:
14+
15+
toolsium completion fish > ~/.config/fish/completions/toolsium.fish
16+
17+
You will need to start a new shell for this setup to take effect.
18+
19+
20+
```
21+
toolsium completion fish [flags]
22+
```
23+
24+
### Options
25+
26+
```
27+
-h, --help help for fish
28+
--no-descriptions disable completion descriptions
29+
```
30+
31+
### Options inherited from parent commands
32+
33+
```
34+
--config string config file (default is $HOME/.toolsium.json)
35+
```
36+
37+
### SEE ALSO
38+
39+
* [toolsium completion](toolsium_completion.md) - Generate the autocompletion script for the specified shell
40+
41+
###### Auto generated by spf13/cobra on 27-Aug-2022
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## toolsium completion powershell
2+
3+
Generate the autocompletion script for powershell
4+
5+
### Synopsis
6+
7+
Generate the autocompletion script for powershell.
8+
9+
To load completions in your current shell session:
10+
11+
toolsium completion powershell | Out-String | Invoke-Expression
12+
13+
To load completions for every new session, add the output of the above command
14+
to your powershell profile.
15+
16+
17+
```
18+
toolsium completion powershell [flags]
19+
```
20+
21+
### Options
22+
23+
```
24+
-h, --help help for powershell
25+
--no-descriptions disable completion descriptions
26+
```
27+
28+
### Options inherited from parent commands
29+
30+
```
31+
--config string config file (default is $HOME/.toolsium.json)
32+
```
33+
34+
### SEE ALSO
35+
36+
* [toolsium completion](toolsium_completion.md) - Generate the autocompletion script for the specified shell
37+
38+
###### Auto generated by spf13/cobra on 27-Aug-2022

0 commit comments

Comments
 (0)