Skip to content

Commit

Permalink
Merge pull request #56 from nerdalize/fix-command_help
Browse files Browse the repository at this point in the history
Show help messages
  • Loading branch information
borismattijssen committed Mar 30, 2017
2 parents 67ccf75 + 3153aec commit 9333ae2
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion command/command.go
Expand Up @@ -28,7 +28,7 @@ func (c *command) Help() string {
}

return fmt.Sprintf(`
%s
%s
%s`, txt, buf.String())
}
Expand Down
2 changes: 1 addition & 1 deletion command/download.go
Expand Up @@ -33,7 +33,7 @@ func DownloadFactory() func() (cmd cli.Command, err error) {
cmd := &Download{
command: &command{
help: "",
synopsis: "fetch the output of a task from cloud storage",
synopsis: "Download a dataset from cloud storage.",
parser: flags.NewNamedParser("nerd download <dataset> <output-dir>", flags.Default),
ui: &cli.BasicUi{
Reader: os.Stdin,
Expand Down
2 changes: 1 addition & 1 deletion command/login.go
Expand Up @@ -31,7 +31,7 @@ func LoginFactory() func() (cmd cli.Command, err error) {
cmd := &Login{
command: &command{
help: "",
synopsis: "setup an authorized session for the cloud",
synopsis: "Setup an authorized session.",
parser: flags.NewNamedParser("nerd login", flags.Default),
ui: &cli.BasicUi{
Reader: os.Stdin,
Expand Down
4 changes: 2 additions & 2 deletions command/logs.go
Expand Up @@ -25,8 +25,8 @@ func LogsFactory() func() (cmd cli.Command, err error) {
cmd := &Logs{
command: &command{
help: "",
synopsis: "retrieve up-to-date feedback from a task",
parser: flags.NewNamedParser("nerd logs <task_id>", flags.Default),
synopsis: "Retrieve up-to-date feedback from a task.",
parser: flags.NewNamedParser("nerd logs <task-ID>", flags.Default),
ui: &cli.BasicUi{
Reader: os.Stdin,
Writer: os.Stderr,
Expand Down
5 changes: 5 additions & 0 deletions command/opts.go
Expand Up @@ -8,5 +8,10 @@ type OutputOpts struct {

//NerdOpts are the options that are applicable to all nerd commands.
type NerdOpts struct {
ConfOpts
}

type ConfOpts struct {
ConfigFile string `long:"config" default:"" default-mask:"" env:"CONFIG" description:"location of config file"`
OutputOpts
}
13 changes: 9 additions & 4 deletions command/run.go
Expand Up @@ -31,8 +31,8 @@ func RunFactory() func() (cmd cli.Command, err error) {
cmd := &Run{
command: &command{
help: "",
synopsis: "create a new compute task for a dataset",
parser: flags.NewNamedParser("nerd run <image> <dataset>", flags.Default),
synopsis: "Run a new compute task.\nOptionally you can give a dataset-ID as the second argument. This dataset-ID will be available as the NERD_DATASET_INPUT env variable inside the container.",
parser: flags.NewNamedParser("nerd run <image> [dataset-ID]", flags.Default),
ui: &cli.BasicUi{
Reader: os.Stdin,
Writer: os.Stderr,
Expand All @@ -55,10 +55,15 @@ func RunFactory() func() (cmd cli.Command, err error) {

//DoRun is called by run and allows an error to be returned
func (cmd *Run) DoRun(args []string) error {
if len(args) < 2 {
if len(args) < 1 {
return fmt.Errorf("not enough arguments, see --help")
}

dataset := ""
if len(args) == 2 {
dataset = args[1]
}

env := make(map[string]string)
for i, e := range cmd.opts.Environment {
split := strings.Split(e, "=")
Expand All @@ -73,7 +78,7 @@ func (cmd *Run) DoRun(args []string) error {
HandleError(err, cmd.opts.VerboseOutput)
}

task, err := client.CreateTask(args[0], args[1], env)
task, err := client.CreateTask(args[0], dataset, env)
if err != nil {
HandleError(err, cmd.opts.VerboseOutput)
}
Expand Down
2 changes: 1 addition & 1 deletion command/status.go
Expand Up @@ -28,7 +28,7 @@ func StatusFactory() func() (cmd cli.Command, err error) {
cmd := &Status{
command: &command{
help: "",
synopsis: "show the status of all queued tasks",
synopsis: "Show the status of all tasks.",
parser: flags.NewNamedParser("nerd status", flags.Default),
ui: &cli.BasicUi{
Reader: os.Stdin,
Expand Down
4 changes: 2 additions & 2 deletions command/upload.go
Expand Up @@ -38,8 +38,8 @@ func UploadFactory() func() (cmd cli.Command, err error) {
cmd := &Upload{
command: &command{
help: "",
synopsis: "push task data as input to cloud storage",
parser: flags.NewNamedParser("nerd upload <path>", flags.Default),
synopsis: "Upload a dataset to cloud storage.\nOptionally you can specify a dataset-ID to append files to that dataset. This is also useful to continue an upload in case a previous try failed.",
parser: flags.NewNamedParser("nerd upload <path> [dataset-ID]", flags.Default),
ui: &cli.BasicUi{
Reader: os.Stdin,
Writer: os.Stderr,
Expand Down
2 changes: 1 addition & 1 deletion command/work.go
Expand Up @@ -51,7 +51,7 @@ func WorkFactory() func() (cmd cli.Command, err error) {
cmd := &Work{
command: &command{
help: "",
synopsis: "start handling tasks on local compute resources",
synopsis: "Start handling tasks on local compute resources.",
parser: flags.NewNamedParser("nerd work", flags.Default),
ui: &cli.BasicUi{
Reader: os.Stdin,
Expand Down
13 changes: 4 additions & 9 deletions main.go
Expand Up @@ -18,19 +18,14 @@ var (
commit = "0000000"
)

type ConfOpts struct {
ConfigFile string `long:"config" default:"" default-mask:"" env:"CONFIG" description:"location of config file"`
command.OutputOpts
}

func init() {
opts := new(ConfOpts)
_, err := flags.NewParser(opts, flags.IgnoreUnknown).ParseArgs(os.Args[1:])
opts := new(command.ConfOpts)
_, err := flags.NewParser(opts, flags.None).ParseArgs(os.Args[1:])
if err == nil {
conf.SetLocation(opts.ConfigFile)
nerd.SetupLogging(opts.VerboseOutput, opts.JSONOutput)
nerd.VersionMessage(version)
}
nerd.SetupLogging(opts.VerboseOutput, opts.JSONOutput)
nerd.VersionMessage(version)
}

func main() {
Expand Down

0 comments on commit 9333ae2

Please sign in to comment.