Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update help info and documentation #487

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/NBISweden/sda-cli/decrypt"
"github.com/NBISweden/sda-cli/download"
"github.com/NBISweden/sda-cli/encrypt"
"github.com/NBISweden/sda-cli/helpers"
"github.com/NBISweden/sda-cli/htsget"
"github.com/NBISweden/sda-cli/list"
"github.com/NBISweden/sda-cli/login"
Expand All @@ -20,10 +19,29 @@ import (

var Version = "0-development"

var Usage = `USAGE: %s -config <s3config-file> <command> [command-args]
var Usage = `Usage: sda-cli [-config CONFIGFILE] <command> [options]

This is a helper tool that can help with common tasks when interacting
with the Sensitive Data Archive (SDA).
A tool for common tasks with the Sensitive Data Archive (SDA)

Commands:
createKey Creates a Crypt4GH key pair
decrypt Decrypt files
download Download files from SDA
encrypt Encrypt files
htsget Get files using htsget
list List files in the SDA
login Login to the SDA
upload Upload files to the SDA

Global options:
-config CONFIGFILE Path to the configuration file

Additional commands:
version Show the version of the tool
help Show this help message
-h, -help Show this help message

Run 'sda-cli help <command>' for more information on a command.
`

// Map of the sub-commands, and their arguments and usage text strings
Expand Down Expand Up @@ -80,9 +98,11 @@ func main() {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}

os.Exit(0)
}

// Parses the command line arguments into a command, and keep the rest
// Parse the command line arguments into a command, and keep the rest
// of the arguments for the subcommand.
func ParseArgs() (string, []string, string) {
var configPath string
Expand Down Expand Up @@ -152,7 +172,7 @@ func ParseArgs() (string, []string, string) {
return command, os.Args, configPath
}

// Prints the main usage string, and the global help or command help
// Print the main usage string, and the global help or command help
// depending on the command argument. Returns an error if the command
// is not recognized.
func Help(command string) error {
Expand All @@ -163,15 +183,7 @@ func Help(command string) error {
}

// print main help
fmt.Fprintf(os.Stderr, Usage, os.Args[0])
fmt.Fprintln(os.Stderr, "The tool can help with these actions:")
for _, info := range Commands {
subcommandUsage := helpers.FormatSubcommandUsage(info.usage)
fmt.Fprint(os.Stderr, subcommandUsage)
}
fmt.Fprintf(os.Stderr,
"use '%s help <command>' to get help with subcommand flags.\n",
os.Args[0])
fmt.Println(Usage)

if command == "help" {
return nil
Expand All @@ -180,7 +192,7 @@ func Help(command string) error {
return fmt.Errorf("unknown command: %s", command)
}

// print subcommand help
// Print subcommand help
fmt.Fprintf(os.Stderr, info.usage+"\n", os.Args[0])
fmt.Fprintln(os.Stderr, "Command line arguments:")
info.args.PrintDefaults()
Expand Down
Loading