Skip to content

Commit

Permalink
better usage string def and improved logic to stdout and stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
nanjiangshu committed Sep 16, 2024
1 parent adc7815 commit 662b686
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions sda-admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ var (
)

// Command-line usage
const usage = `Usage:
sda-admin [-uri URI] [-token TOKEN] <command> [options]
const usage = `Usage: sda-admin [-uri URI] [-token TOKEN] <command> [options]
Commands:
user list List all users.
Expand Down Expand Up @@ -82,17 +81,15 @@ Options:
-filepath FILEPATH Specify the path of the file to ingest.
-user USERNAME Specify the username associated with the file.`

var fileAccessionUsage = `
Usage: sda-admin file set-accession -filepath FILEPATH -user USERNAME -accession-id ACCESSION_ID
var fileAccessionUsage = `Usage: sda-admin file set-accession -filepath FILEPATH -user USERNAME -accession-id ACCESSION_ID
Assign accession ID to a file and associate it with a user.
Options:
-filepath FILEPATH Specify the path of the file to assign the accession ID.
-user USERNAME Specify the username associated with the file.
-accession-id ID Specify the accession ID to assign to the file.`

var datasetUsage = `
Create a dataset:
var datasetUsage = `Create a dataset:
Usage: sda-admin dataset create -dataset-id DATASET_ID [ACCESSION_ID ...]
Create a dataset from a list of accession IDs and a dataset ID.
Expand All @@ -106,23 +103,20 @@ Options:
Use 'sda-admin help dataset <command>' for information on a specific command.`

var datasetCreateUsage = `
Usage: sda-admin dataset create -dataset-id DATASET_ID [ACCESSION_ID ...]
var datasetCreateUsage = `Usage: sda-admin dataset create -dataset-id DATASET_ID [ACCESSION_ID ...]
Create a dataset from a list of accession IDs and a dataset ID.
Options:
-dataset-id DATASET_ID Specify the unique identifier for the dataset.
[ACCESSION_ID ...] (For dataset create) Specify one or more accession IDs to include in the dataset.`

var datasetReleaseUsage = `
Usage: sda-admin dataset release -dataset-id DATASET_ID
var datasetReleaseUsage = `Usage: sda-admin dataset release -dataset-id DATASET_ID
Release a dataset for downloading based on its dataset ID.
Options:
-dataset-id DATASET_ID Specify the unique identifier for the dataset.`

var versionUsage = `
Usage: sda-admin version
var versionUsage = `Usage: sda-admin version
Show the version information for sda-admin.`

func printVersion() {
Expand Down Expand Up @@ -201,9 +195,9 @@ func handleHelpCommand() error {
func handleHelpUser() error {
switch {
case flag.NArg() == 2:
fmt.Fprint(os.Stderr, userUsage)
fmt.Println(userUsage)
case flag.Arg(2) == "list":
fmt.Fprint(os.Stderr, userListUsage)
fmt.Println(userListUsage)
default:
return fmt.Errorf("unknown subcommand '%s' for '%s'.\n%s", flag.Arg(2), flag.Arg(1), userUsage)
}
Expand All @@ -214,7 +208,7 @@ func handleHelpUser() error {
func handleHelpFile() error {
switch {
case flag.NArg() == 2:
fmt.Fprint(os.Stderr, fileUsage)
fmt.Println(fileUsage)
case flag.Arg(2) == "list":
fmt.Println(fileListUsage)
case flag.Arg(2) == "ingest":
Expand Down Expand Up @@ -328,8 +322,6 @@ func handleFileIngestCommand() error {
return fmt.Errorf("error: failed to ingest file, reason: %v", err)
}

fmt.Println("File ingestion triggered successfully.")

return nil
}

Expand Down Expand Up @@ -455,8 +447,7 @@ func main() {
case "version":
printVersion()
default:
fmt.Fprintf(os.Stderr, "Unknown command '%s'.\n", flag.Arg(0))
fmt.Fprint(os.Stderr, usage, "\n")
fmt.Fprintf(os.Stderr, "unknown command '%s'.\n%s\n", flag.Arg(0), usage)
os.Exit(1)
}

Expand Down

0 comments on commit 662b686

Please sign in to comment.