Skip to content

Commit

Permalink
feat: Add version subcommand
Browse files Browse the repository at this point in the history
Will be populated by goreleaser automatically.
  • Loading branch information
AdrianoKF committed Aug 6, 2022
1 parent 8d3b584 commit 4a94eab
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
5 changes: 2 additions & 3 deletions cmd/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Copyright © 2022 Adrian Rumpold <a.rumpold@gmail.com>
*/
package cmd

Expand Down Expand Up @@ -57,5 +56,5 @@ to quickly create a Cobra application.`,
}

func init() {
rootCmd.AddCommand(clientCmd)
RootCmd.AddCommand(clientCmd)
}
15 changes: 6 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "go-clip",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
Expand All @@ -19,22 +19,19 @@ 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) { },
}

// 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()
err := RootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.PersistentFlags().IntP("port", "p", 9090, "port to listen on")
rootCmd.PersistentFlags().String("secret", "", "secret key for encryption / message authentication")
RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
RootCmd.PersistentFlags().IntP("port", "p", 9090, "port to listen on")
RootCmd.PersistentFlags().String("secret", "", "secret key for encryption / message authentication")
}
5 changes: 2 additions & 3 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Copyright © 2022 Adrian Rumpold <a.rumpold@gmail.com>
*/
package cmd

Expand Down Expand Up @@ -67,5 +66,5 @@ to quickly create a Cobra application.`,
}

func init() {
rootCmd.AddCommand(serverCmd)
RootCmd.AddCommand(serverCmd)
}
24 changes: 24 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,35 @@ Copyright © 2022 Adrian Rumpold <a.rumpold@gmail.com>
package main

import (
"fmt"

"github.com/AdrianoKF/go-clip/cmd"
"github.com/AdrianoKF/go-clip/internal/util"
"github.com/spf13/cobra"
)

var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Version will output the current build information",
Long: ``,
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("Version: %s\n", version)
fmt.Printf("Commit: %s\n", commit)
fmt.Printf("Date: %s\n", date)
fmt.Printf("Built by: %s\n", builtBy)
},
}

func main() {
util.InitializeLogging(true)

cmd.RootCmd.AddCommand(versionCmd)
cmd.Execute()
}

0 comments on commit 4a94eab

Please sign in to comment.