Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #453 from findy-network/flags-integration
Browse files Browse the repository at this point in the history
flags integration
  • Loading branch information
lainio authored Nov 6, 2023
2 parents c83c90c + 184142d commit 4ac4d39
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ setup environment and especially install `libindy`.
2. Clone [findy-agent](https://github.com/findy-network/findy-agent) (this repo)
3. Install needed Go packages: `make deps`.
4. Install the command line application: `make install`
5. Verify the installation: `findy-agent -version`
5. Verify the installation: `findy-agent version`

It should output similar to:
`findy-agent version 0.xx.xx`
Expand Down
24 changes: 15 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package cmd

import (
goflag "flag"
"fmt"
"log"
"os"
"strings"

"github.com/findy-network/findy-agent/agent/utils"
"github.com/findy-network/findy-agent/cmds/agency"
"github.com/findy-network/findy-common-go/utils"
"github.com/golang/glog"
"github.com/lainio/err2"
"github.com/lainio/err2/assert"
"github.com/lainio/err2/try"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand All @@ -22,19 +21,24 @@ const envPrefix = "FCLI"
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
SilenceUsage: true,
Version: utils.Version,
Use: "findy-agent",
Short: "Findy agent cli tool",
Long: `
Findy agent cli tool
`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
assert.SetDefault(assert.Production)
err2.SetPanicTracer(os.Stderr)
agency.ParseLoggingArgs(rootFlags.logging)
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
defer err2.Handle(&err)

// NOTE! Very important. Adds support for std flag pkg users: glog, err2
goflag.Parse()

// let's support our old logging env
utils.ParseLoggingArgs(rootFlags.logging)
try.To(goflag.Set("logtostderr", "true"))
handleViperFlags(cmd)
glog.CopyStandardLogTo("ERROR") // for err2
aCmd.PreRun()
//aCmd.PreRun()
return nil
},
}

Expand Down Expand Up @@ -105,6 +109,8 @@ func init() {

try.To(BindEnvs(rootEnvs, ""))

// NOTE! Very important. Adds support for std flag pkg users: glog, err2
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
}

func initConfig() {
Expand Down
32 changes: 32 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"fmt"

"github.com/findy-network/findy-agent/agent/utils"
"github.com/lainio/err2"
"github.com/lainio/err2/try"
"github.com/spf13/cobra"
)

var versionDoc = ``

var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints the version and build information of the CLI tool",
Long: versionDoc,
RunE: func(c *cobra.Command, args []string) (err error) {
defer err2.Handle(&err)

try.To1(fmt.Println(utils.Version))
return nil
},
}

func init() {
defer err2.Catch(err2.Err(func(err error) {
fmt.Println(err)
}))

rootCmd.AddCommand(versionCmd)
}

0 comments on commit 4ac4d39

Please sign in to comment.