Skip to content

Commit

Permalink
feat: add run command
Browse files Browse the repository at this point in the history
  • Loading branch information
adikari committed Sep 5, 2022
1 parent 7394963 commit a68fb75
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ clean: |
dist/:
mkdir -p dist

build: safebox
build: clean safebox

safebox:
CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o $@
Expand Down
23 changes: 18 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,30 @@ import (
"github.com/spf13/cobra"
)

var RootCmd = &cobra.Command{
Use: "SafeBox",
var (
stage string
config string
)

var rootCmd = &cobra.Command{
Use: "safebox",
Short: "SafeBox is a secret manager CLI program",
Long: `A Fast and Flexible secret manager built with love by adikari in Go.`,
Run: func(cmd *cobra.Command, args []string) {
// Do Stuff Here
cmd.Usage()
},
}

func Execute() {
if cmd, err := RootCmd.ExecuteC(); err != nil {
func init() {
rootCmd.Flags().StringVarP(&stage, "stage", "s", "", "stage to deploy to")
rootCmd.Flags().StringVarP(&config, "config", "c", "safebox.yml", "path to safebox configuration file")
rootCmd.MarkFlagRequired("stage")
}

func Execute(version string) {
rootCmd.Version = version

if cmd, err := rootCmd.ExecuteC(); err != nil {
if strings.Contains(err.Error(), "arg(s)") || strings.Contains(err.Error(), "usage") {
cmd.Usage()
}
Expand Down
24 changes: 24 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"log"

"github.com/spf13/cobra"
)

// runCmd represents the exec command
var runCmd = &cobra.Command{
Use: "run",
Short: "Deploys all configurations specified in config file",
RunE: execute,
Example: `TODO`,
}

func init() {
rootCmd.AddCommand(runCmd)
}

func execute(cmd *cobra.Command, args []string) error {
log.Print(stage)
return nil
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/adikari/safebox/v2

go 1.19

require github.com/spf13/cobra v1.5.0
require (
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.5.0
)

require (
github.com/inconshreveable/mousetrap v1.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package main

import "github.com/adikari/safebox/v2/cmd"

var (
Version = "dev"
)

func main() {
cmd.Execute()
cmd.Execute(Version)
}

0 comments on commit a68fb75

Please sign in to comment.