mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 21:21:03 +00:00
feat(cli): add --version flag (#29)
This commit is contained in:
parent
a67b510284
commit
1ede0bef10
2 changed files with 28 additions and 26 deletions
|
|
@ -1,31 +1,45 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var logger *slog.Logger
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "releaser-pleaser",
|
||||
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) { },
|
||||
Short: "",
|
||||
Long: ``,
|
||||
Version: version(),
|
||||
}
|
||||
|
||||
func version() string {
|
||||
vcsrevision := "unknown"
|
||||
vcsdirty := ""
|
||||
|
||||
buildInfo, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
fmt.Println(buildInfo.String())
|
||||
for _, setting := range buildInfo.Settings {
|
||||
switch setting.Key {
|
||||
case "vcs.revision":
|
||||
vcsrevision = setting.Value
|
||||
case "vcs.modified":
|
||||
if setting.Value == "true" {
|
||||
vcsdirty = " (dirty)"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vcsrevision + vcsdirty
|
||||
}
|
||||
|
||||
// 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() {
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
|
|
@ -38,13 +52,4 @@ func init() {
|
|||
Level: slog.LevelDebug,
|
||||
}))
|
||||
|
||||
// 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/.releaser-pleaser.yaml)")
|
||||
|
||||
// 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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
rp "github.com/apricote/releaser-pleaser"
|
||||
)
|
||||
|
||||
// runCmd represents the run command
|
||||
var runCmd = &cobra.Command{
|
||||
Use: "run",
|
||||
RunE: run,
|
||||
|
|
@ -25,8 +24,6 @@ var (
|
|||
func init() {
|
||||
rootCmd.AddCommand(runCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
runCmd.PersistentFlags().StringVar(&flagForge, "forge", "", "")
|
||||
runCmd.PersistentFlags().StringVar(&flagBranch, "branch", "main", "")
|
||||
runCmd.PersistentFlags().StringVar(&flagOwner, "owner", "", "")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue