From bcd2d481d82965e3e14bbfc83f9048ab0fa736fe Mon Sep 17 00:00:00 2001 From: Will Johnson Date: Sun, 1 Jul 2018 23:04:30 +0100 Subject: [PATCH] Generate Docs Script Generate Binaries Command Improved --- .gitignore | 2 +- build/build_binaries.sh | 29 +++++++++++++++++++++++++++++ build/generate_docs.go | 25 +++++++++++++++++++++++++ cmd/add.go | 2 +- cmd/copy.go | 2 +- cmd/list.go | 2 +- cmd/root.go | 8 ++++---- docs/param.md | 22 ++++++++++++++++++++++ docs/param_add.md | 30 ++++++++++++++++++++++++++++++ docs/param_copy.md | 30 ++++++++++++++++++++++++++++++ docs/param_list.md | 31 +++++++++++++++++++++++++++++++ 11 files changed, 175 insertions(+), 8 deletions(-) create mode 100755 build/build_binaries.sh create mode 100644 build/generate_docs.go create mode 100644 docs/param.md create mode 100644 docs/param_add.md create mode 100644 docs/param_copy.md create mode 100644 docs/param_list.md diff --git a/.gitignore b/.gitignore index cffe3a9..68ad9b9 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ github.com # Complied binaries -cmd/param/param-* +bin/ ### macOS ### # General diff --git a/build/build_binaries.sh b/build/build_binaries.sh new file mode 100755 index 0000000..a66d951 --- /dev/null +++ b/build/build_binaries.sh @@ -0,0 +1,29 @@ + +PLATFORMS="darwin/amd64 linux/amd64" + +type setopt >/dev/null 2>&1 + +SCRIPT_NAME=`basename "$0"` +FAILURES="" + +if [ -z "${GOPATH}" ]; then + GOPATH="~/go" +fi +BIN_PATH="${GOPATH}/src/github.com/willjcj/param/bin" + +for PLATFORM in $PLATFORMS; do + GOOS=${PLATFORM%/*} + GOARCH=${PLATFORM#*/} + BIN_FILENAME="${BIN_PATH}/param-${GOOS}-${GOARCH}" + + CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${BIN_FILENAME} $@" + echo "${CMD}" + eval $CMD || FAILURES="${FAILURES} ${PLATFORM}" +done + +# eval errors +if [[ "${FAILURES}" != "" ]]; then + echo "" + echo "${SCRIPT_NAME} failed on: ${FAILURES}" + exit 1 +fi diff --git a/build/generate_docs.go b/build/generate_docs.go new file mode 100644 index 0000000..52ac497 --- /dev/null +++ b/build/generate_docs.go @@ -0,0 +1,25 @@ +package main + +import ( + "go/build" + "log" + "os" + "path" + + "github.com/spf13/cobra/doc" + "github.com/willjcj/param/cmd" +) + +func main() { + gopath := os.Getenv("GOPATH") + if gopath == "" { + gopath = build.Default.GOPATH + } + + docsPath := path.Join(gopath, "src", "github.com", "willjcj", "param", "docs") + + err := doc.GenMarkdownTree(cmd.RootCmd, docsPath) + if err != nil { + log.Fatal(err) + } +} diff --git a/cmd/add.go b/cmd/add.go index cbf7aae..13756a6 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -17,5 +17,5 @@ var addCmd = &cobra.Command{ } func init() { - rootCmd.AddCommand(addCmd) + RootCmd.AddCommand(addCmd) } diff --git a/cmd/copy.go b/cmd/copy.go index 03dd09e..606c688 100644 --- a/cmd/copy.go +++ b/cmd/copy.go @@ -21,7 +21,7 @@ var copyCmd = &cobra.Command{ } func init() { - rootCmd.AddCommand(copyCmd) + RootCmd.AddCommand(copyCmd) copyCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Also print parameter value to the stdout.") } diff --git a/cmd/list.go b/cmd/list.go index 1097a5a..5f9ddc6 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -21,7 +21,7 @@ var listCmd = &cobra.Command{ } func init() { - rootCmd.AddCommand(listCmd) + RootCmd.AddCommand(listCmd) listCmd.Flags().StringVarP(&prefixes, "prefix", "p", "", "Prefixes to fileter by") } diff --git a/cmd/root.go b/cmd/root.go index d23daed..aeeebc4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -11,16 +11,16 @@ import ( var cfgFile string -var rootCmd = &cobra.Command{ +var RootCmd = &cobra.Command{ Use: "param", Short: "Tools to improve Parameter Store on the command line.", Long: "Param is a cli tool to improve interacting with AWS Parameter Store.", } // 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. +// This is called by main.main(). It only needs to happen once to the RootCmd. func Execute() { - if err := rootCmd.Execute(); err != nil { + if err := RootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } @@ -32,7 +32,7 @@ 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. - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.param.yaml)") + RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.param.yaml)") } // initConfig reads in config file and ENV variables if set. diff --git a/docs/param.md b/docs/param.md new file mode 100644 index 0000000..9c36f44 --- /dev/null +++ b/docs/param.md @@ -0,0 +1,22 @@ +## param + +Tools to improve Parameter Store on the command line. + +### Synopsis + +Param is a cli tool to improve interacting with AWS Parameter Store. + +### Options + +``` + --config string config file (default is $HOME/.param.yaml) + -h, --help help for param +``` + +### SEE ALSO + +* [param add](param_add.md) - Add a paramter to Parameter Store. +* [param copy](param_copy.md) - Copy a parameter to clipboard. +* [param list](param_list.md) - List parameters in Parameter Store. + +###### Auto generated by spf13/cobra on 1-Jul-2018 diff --git a/docs/param_add.md b/docs/param_add.md new file mode 100644 index 0000000..5d03ae1 --- /dev/null +++ b/docs/param_add.md @@ -0,0 +1,30 @@ +## param add + +Add a paramter to Parameter Store. + +### Synopsis + +Add a paramter to Parameter Store. + Doesn't work yet. + +``` +param add [flags] +``` + +### Options + +``` + -h, --help help for add +``` + +### Options inherited from parent commands + +``` + --config string config file (default is $HOME/.param.yaml) +``` + +### SEE ALSO + +* [param](param.md) - Tools to improve Parameter Store on the command line. + +###### Auto generated by spf13/cobra on 1-Jul-2018 diff --git a/docs/param_copy.md b/docs/param_copy.md new file mode 100644 index 0000000..cf89a27 --- /dev/null +++ b/docs/param_copy.md @@ -0,0 +1,30 @@ +## param copy + +Copy a parameter to clipboard. + +### Synopsis + +Copy the specified SSM Parameter from Paramter Store to your clipboard. + +``` +param copy parameter_name [flags] +``` + +### Options + +``` + -h, --help help for copy + -v, --verbose Also print parameter value to the stdout. +``` + +### Options inherited from parent commands + +``` + --config string config file (default is $HOME/.param.yaml) +``` + +### SEE ALSO + +* [param](param.md) - Tools to improve Parameter Store on the command line. + +###### Auto generated by spf13/cobra on 1-Jul-2018 diff --git a/docs/param_list.md b/docs/param_list.md new file mode 100644 index 0000000..ab2d9e0 --- /dev/null +++ b/docs/param_list.md @@ -0,0 +1,31 @@ +## param list + +List parameters in Parameter Store. + +### Synopsis + +List all parameters from parameter store with an optional prefix. + Results are sorted in alphabetical order. + +``` +param list [flags] +``` + +### Options + +``` + -h, --help help for list + -p, --prefix string Prefixes to fileter by +``` + +### Options inherited from parent commands + +``` + --config string config file (default is $HOME/.param.yaml) +``` + +### SEE ALSO + +* [param](param.md) - Tools to improve Parameter Store on the command line. + +###### Auto generated by spf13/cobra on 1-Jul-2018