diff --git a/cmd/cardano-up/main.go b/cmd/cardano-up/main.go index f732408..0808302 100644 --- a/cmd/cardano-up/main.go +++ b/cmd/cardano-up/main.go @@ -15,9 +15,9 @@ package main import ( - "fmt" + "os" - "github.com/blinklabs-io/cardano-up/internal/version" + "github.com/spf13/cobra" ) const ( @@ -25,5 +25,26 @@ const ( ) func main() { - fmt.Printf("%s %s\n", programName, version.GetVersionString()) + rootCmd := &cobra.Command{ + Use: programName, + /* + 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.`, + */ + } + + // Add subcommands + rootCmd.AddCommand( + versionCommand(), + ) + + if err := rootCmd.Execute(); err != nil { + // NOTE: we purposely don't display the error, since cobra will have already displayed it + os.Exit(1) + } } diff --git a/cmd/cardano-up/version.go b/cmd/cardano-up/version.go new file mode 100644 index 0000000..48e791d --- /dev/null +++ b/cmd/cardano-up/version.go @@ -0,0 +1,32 @@ +// Copyright 2023 Blink Labs Software +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "fmt" + + "github.com/blinklabs-io/cardano-up/internal/version" + "github.com/spf13/cobra" +) + +func versionCommand() *cobra.Command { + return &cobra.Command{ + Use: "version", + Short: "Displays the version", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("%s %s\n", programName, version.GetVersionString()) + }, + } +} diff --git a/go.mod b/go.mod index fa2f2a6..c2cd72f 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module github.com/blinklabs-io/cardano-up go 1.20 + +require github.com/spf13/cobra v1.8.0 + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d0e8c2c --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=