Skip to content

Commit

Permalink
make 'version' flag global
Browse files Browse the repository at this point in the history
  • Loading branch information
consolethinks committed Jul 19, 2024
1 parent 456197a commit 5e4f554
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion cmd/commands/datasetArchiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func init() {
datasetArchiverCmd.Flags().Bool("localenv", false, "Use local environment (local) instead or production")
datasetArchiverCmd.Flags().Bool("devenv", false, "Use development environment instead or production")
datasetArchiverCmd.Flags().Bool("noninteractive", false, "Defines if no questions will be asked, just do it - make sure you know what you are doing")
datasetArchiverCmd.Flags().Bool("version", false, "Show version number and exit")

datasetArchiverCmd.MarkFlagsMutuallyExclusive("testenv", "localenv", "devenv")
}
1 change: 0 additions & 1 deletion cmd/commands/datasetCleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func init() {
datasetCleanerCmd.Flags().Bool("nonInteractive", false, "Defines if no questions will be asked, just do it - make sure you know what you are doing")
datasetCleanerCmd.Flags().Bool("testenv", false, "Use test environment (qa) instead of production environment")
datasetCleanerCmd.Flags().Bool("devenv", false, "Use development environment instead of production environment (developers only)")
datasetCleanerCmd.Flags().Bool("version", false, "Show version number and exit")

datasetCleanerCmd.MarkFlagsMutuallyExclusive("testenv", "devenv")
}
1 change: 0 additions & 1 deletion cmd/commands/datasetGetProposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func init() {
datasetGetProposalCmd.Flags().String("field", "", "Defines optional field name , whose value should be returned instead of full information")
datasetGetProposalCmd.Flags().Bool("testenv", false, "Use test environment (qa) instead or production")
datasetGetProposalCmd.Flags().Bool("devenv", false, "Use development environment instead or production")
datasetGetProposalCmd.Flags().Bool("version", false, "Show version number and exit")

datasetGetProposalCmd.MarkFlagsMutuallyExclusive("testenv", "devenv")
}
1 change: 0 additions & 1 deletion cmd/commands/datasetIngestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ func init() {
datasetIngestorCmd.Flags().Bool("allowexistingsource", false, "Defines if existing sourceFolders can be reused")
datasetIngestorCmd.Flags().String("addattachment", "", "Filename of image to attach (single dataset case only)")
datasetIngestorCmd.Flags().String("addcaption", "", "Optional caption to be stored with attachment (single dataset case only)")
datasetIngestorCmd.Flags().Bool("version", false, "Show version number and exit")

datasetIngestorCmd.MarkFlagsMutuallyExclusive("testenv", "devenv", "localenv", "tunnelenv")
}
1 change: 0 additions & 1 deletion cmd/commands/datasetPublishData.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ func init() {
// datasetPublishDataCmd.Flags().String("ownergroup", "", "Defines to publish only datasets of the specified ownerGroup")
datasetPublishDataCmd.Flags().Bool("testenv", false, "Use test environment (qa) (default is to use production system)")
datasetPublishDataCmd.Flags().Bool("devenv", false, "Use development environment (default is to use production system)")
datasetPublishDataCmd.Flags().Bool("version", false, "Show version number and exit")

datasetPublishDataCmd.MarkFlagsMutuallyExclusive("testenv", "devenv")
}
1 change: 0 additions & 1 deletion cmd/commands/datasetPublishDataRetrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func init() {
datasetPublishDataRetrieveCmd.Flags().String("publisheddata", "", "Defines to publish data from a given publishedData document ID")
datasetPublishDataRetrieveCmd.Flags().Bool("testenv", false, "Use test environment (qa) (default is to use production system)")
datasetPublishDataRetrieveCmd.Flags().Bool("devenv", false, "Use development environment (default is to use production system)")
datasetPublishDataRetrieveCmd.Flags().Bool("version", false, "Show version number and exit")

datasetPublishDataRetrieveCmd.MarkFlagsMutuallyExclusive("testenv", "devenv")
}
1 change: 0 additions & 1 deletion cmd/commands/datasetRetriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func init() {
datasetRetrieverCmd.Flags().String("ownergroup", "", "Defines to fetch only datasets of the specified ownerGroup (default is to fetch all available datasets)")
datasetRetrieverCmd.Flags().Bool("testenv", false, "Use test environment (qa) (default is to use production system)")
datasetRetrieverCmd.Flags().Bool("devenv", false, "Use development environment (default is to use production system)")
datasetRetrieverCmd.Flags().Bool("version", false, "Show version number and exit")

datasetRetrieverCmd.MarkFlagsMutuallyExclusive("testenv", "devenv")
}
13 changes: 11 additions & 2 deletions cmd/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
Expand All @@ -12,8 +13,15 @@ var rootCmd = &cobra.Command{
Long: `This library comprises a few subcommands for managing SciCat
and datasets on it, as well as interacting with the archival system connected
to it.`,
// uncomment the next line if there's a default action
// Run: func(cmd *cobra.Command, args []string) { },
Run: func(cmd *cobra.Command, args []string) {
version, _ := cmd.Flags().GetBool("version")
if version {
fmt.Printf("%s\n", VERSION)
return
}
fmt.Print("No action was specified.\n\n")
cmd.Help()
},
}

func Execute() {
Expand All @@ -29,4 +37,5 @@ func init() {
rootCmd.PersistentFlags().StringP("user", "u", "", "Defines optional username:password string")
rootCmd.PersistentFlags().String("token", "", "Defines optional API token instead of username:password")
rootCmd.PersistentFlags().StringP("config", "c", "", "A path to a config file for connecting to SciCat and transfer services")
rootCmd.PersistentFlags().BoolP("version", "v", false, "Show version")
}
1 change: 0 additions & 1 deletion cmd/commands/waitForJobFinished.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ func init() {
waitForJobFinishedCmd.Flags().String("job", "", "Defines the job id to poll")
waitForJobFinishedCmd.Flags().Bool("testenv", false, "Use test environment (qa) instead or production")
waitForJobFinishedCmd.Flags().Bool("devenv", false, "Use development environment instead or production")
waitForJobFinishedCmd.Flags().Bool("version", false, "Show version number and exit")

waitForJobFinishedCmd.MarkFlagsMutuallyExclusive("testenv", "devenv")
}

0 comments on commit 5e4f554

Please sign in to comment.