Skip to content

Commit

Permalink
add common flags that are shared between commands (user, token, config)
Browse files Browse the repository at this point in the history
  • Loading branch information
consolethinks committed Jul 19, 2024
1 parent 105b990 commit 456197a
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/commands/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestArgs(t *testing.T) {
//flag.CommandLine = flag.NewFlagSet(test.name, flag.ExitOnError)
datasetUtils.TestArgs = func(args []interface{}) {
passing := true
for i, _ := range test.expectedArgs {
for i := range test.expectedArgs {
if test.expectedArgs[i] != args[i] {
t.Logf("'%v' is not correct, expected: '%s'", args[i], test.expectedArgs[i])
passing = false
Expand Down
2 changes: 0 additions & 2 deletions cmd/commands/datasetArchiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ For further help see "` + MANUAL + `"`,
func init() {
rootCmd.AddCommand(datasetArchiverCmd)

datasetArchiverCmd.Flags().String("user", "", "Defines optional username and password")
datasetArchiverCmd.Flags().String("token", "", "Defines optional API token instead of username:password")
datasetArchiverCmd.Flags().Int("tapecopies", 1, "Number of tapecopies to be used for archiving")
datasetArchiverCmd.Flags().Bool("testenv", false, "Use test environment (qa) instead or production")
datasetArchiverCmd.Flags().Bool("localenv", false, "Use local environment (local) instead or production")
Expand Down
2 changes: 0 additions & 2 deletions cmd/commands/datasetCleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +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().String("user", "", "Defines optional username:password string")
datasetCleanerCmd.Flags().String("token", "", "Defines optional API token instead of username:password")
datasetCleanerCmd.Flags().Bool("version", false, "Show version number and exit")

datasetCleanerCmd.MarkFlagsMutuallyExclusive("testenv", "devenv")
Expand Down
2 changes: 0 additions & 2 deletions cmd/commands/datasetGetProposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ For further help see "` + MANUAL + `"`,
func init() {
rootCmd.AddCommand(datasetGetProposalCmd)

datasetGetProposalCmd.Flags().String("user", "", "Defines optional username and password")
datasetGetProposalCmd.Flags().String("token", "", "Defines optional API token instead of username:password")
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")
Expand Down
2 changes: 0 additions & 2 deletions cmd/commands/datasetIngestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,6 @@ func init() {
datasetIngestorCmd.Flags().Bool("localenv", false, "Use local environment instead of production environment (developers only)")
datasetIngestorCmd.Flags().Bool("tunnelenv", false, "Use tunneled API server at port 5443 to access development instance (developers only)")
datasetIngestorCmd.Flags().Bool("noninteractive", false, "If set no questions will be asked and the default settings for all undefined flags will be assumed")
datasetIngestorCmd.Flags().String("user", "", "Defines optional username:password string. This can be used both for access to the data catalog API and for access to the intermediate storage server for the decentral use case")
datasetIngestorCmd.Flags().String("token", "", "Defines API token for access to the data catalog API. It is now mandatory for normal user accounts, but optional for functional accounts. It takes precedence over username/pw.")
datasetIngestorCmd.Flags().Bool("copy", false, "Defines if files should be copied from your local system to a central server before ingest (i.e. your data is not centrally available and therefore needs to be copied ='decentral' case). copyFlag has higher priority than nocopyFlag. If neither flag is defined the tool will try to make the best guess.")
datasetIngestorCmd.Flags().Bool("nocopy", false, "Defines if files should *not* be copied from your local system to a central server before ingest (i.e. your data is centrally available and therefore does not need to be copied ='central' case).")
datasetIngestorCmd.Flags().Int("tapecopies", 0, "Number of tapecopies to be used for archiving")
Expand Down
2 changes: 0 additions & 2 deletions cmd/commands/datasetPublishData.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ func init() {
datasetPublishDataCmd.Flags().String("publisheddata", "", "Defines to publish data froma given publishedData document ID")
// datasetPublishDataCmd.Flags().String("dataset", "", "Defines single datasetId to publish")
// datasetPublishDataCmd.Flags().String("ownergroup", "", "Defines to publish only datasets of the specified ownerGroup")
datasetPublishDataCmd.Flags().String("user", "", "Defines optional username:password string")
datasetPublishDataCmd.Flags().String("token", "", "Defines optional API token instead of username:password")
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")
Expand Down
2 changes: 0 additions & 2 deletions cmd/commands/datasetPublishDataRetrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ func init() {

datasetPublishDataRetrieveCmd.Flags().Bool("retrieve", false, "Defines if this command is meant to actually retrieve data (default: retrieve actions are only displayed)")
datasetPublishDataRetrieveCmd.Flags().String("publisheddata", "", "Defines to publish data from a given publishedData document ID")
datasetPublishDataRetrieveCmd.Flags().String("user", "", "Defines optional username:password string")
datasetPublishDataRetrieveCmd.Flags().String("token", "", "Defines optional API token instead of username:password")
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")
Expand Down
2 changes: 0 additions & 2 deletions cmd/commands/datasetRetriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ func init() {
rootCmd.AddCommand(datasetRetrieverCmd)

datasetRetrieverCmd.Flags().Bool("retrieve", false, "Defines if this command is meant to actually copy data to the local system (default nothing is done)")
datasetRetrieverCmd.Flags().String("user", "", "Defines optional username and password (default is to prompt for username and password)")
datasetRetrieverCmd.Flags().String("token", "", "Defines optional API token instead of username:password")
datasetRetrieverCmd.Flags().Bool("nochksum", false, "Switch off chksum verification step (default checksum tests are done)")
datasetRetrieverCmd.Flags().String("dataset", "", "Defines single dataset to retrieve (default all available datasets)")
datasetRetrieverCmd.Flags().String("ownergroup", "", "Defines to fetch only datasets of the specified ownerGroup (default is to fetch all available datasets)")
Expand Down
6 changes: 6 additions & 0 deletions cmd/commands/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/paulscherrerinstitute/scicat/datasetUtils"
"github.com/spf13/pflag"
)

func TestMainFlags(t *testing.T) {
Expand Down Expand Up @@ -380,6 +381,11 @@ func TestMainFlags(t *testing.T) {
}
}

rootCmd.PersistentFlags().VisitAll(func(flag *pflag.Flag) {
flag.Value.Set(flag.DefValue)
flag.Changed = false
})

rootCmd.SetArgs(test.args)
Execute()
})
Expand Down
4 changes: 4 additions & 0 deletions cmd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ func Execute() {

func init() {
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

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")
}
2 changes: 0 additions & 2 deletions cmd/commands/waitForJobFinished.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ var waitForJobFinishedCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(waitForJobFinishedCmd)

waitForJobFinishedCmd.Flags().String("user", "", "Defines optional username and password")
waitForJobFinishedCmd.Flags().String("token", "", "Defines optional API token instead of username:password")
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")
Expand Down

0 comments on commit 456197a

Please sign in to comment.