-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gofmt and govet code, read and contributors update
- Loading branch information
Showing
9 changed files
with
62 additions
and
42 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 |
---|---|---|
@@ -1,42 +1,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var cfgFile string | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "{{cookiecutter.app_name}}", | ||
Short: "A brief description of your application", | ||
Long: `A longer description that spans multiple lines and likely contains | ||
Use: "generated code example", | ||
Short: "A brief description of your application", | ||
Long: `A longer description that spans multiple lines and likely contains | ||
examples and usage of using your application. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
// Run: func(cmd *cobra.Command, args []string) { }, | ||
// 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() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize() | ||
cobra.OnInitialize() | ||
|
||
// 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") | ||
} | ||
// 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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"fmt" | ||
"github.com/{{cookiecutter.github_username}}/{{cookiecutter.app_name}}/version" | ||
"fmt" | ||
"github.com/lacion/cookiecutter_golang_example/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// versionCmd represents the version command | ||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number of {{cookiecutter.app_name}}", | ||
Long: `All software has versions. This is {{cookiecutter.app_name}}`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("Build Date:", version.BuildDate) | ||
fmt.Println("Git Commit:", version.GitCommit) | ||
fmt.Println("Version:", version.Version) | ||
fmt.Println("Go Version:", version.GoVersion) | ||
fmt.Println("OS / Arch:", version.OsArch) | ||
}, | ||
Use: "version", | ||
Short: "Print the version number of generated code example", | ||
Long: `All software has versions. This is generated code example`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("Build Date:", version.BuildDate) | ||
fmt.Println("Git Commit:", version.GitCommit) | ||
fmt.Println("Version:", version.Version) | ||
fmt.Println("Go Version:", version.GoVersion) | ||
fmt.Println("OS / Arch:", version.OsArch) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} | ||
rootCmd.AddCommand(versionCmd) | ||
} |
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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
package version | ||
|
||
import ( | ||
"runtime" | ||
"fmt" | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
// The git commit that was compiled. This will be filled in by the compiler. | ||
// GitCommit returns the git commit that was compiled. This will be filled in by the compiler. | ||
var GitCommit string | ||
|
||
// The main version number that is being run at the moment. | ||
// Version returns the main version number that is being run at the moment. | ||
const Version = "0.1.0" | ||
|
||
// BuildDate returns the date the binary was built | ||
var BuildDate = "" | ||
|
||
// GoVersion returns the version of the go runtime used to compile the binary | ||
var GoVersion = runtime.Version() | ||
|
||
var OsArch = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH) | ||
// OsArch returns the os and arch used to build the binary | ||
var OsArch = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH) |