Skip to content

Commit

Permalink
Fix subcommand synopsis for options
Browse files Browse the repository at this point in the history
Closes #162
  • Loading branch information
davetron5000 committed Jan 18, 2014
1 parent f17b254 commit 0b9f74e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 27 deletions.
53 changes: 40 additions & 13 deletions features/todo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ Feature: The todo app has a nice user interface
list - List things, such as tasks or contexts
SYNOPSIS
todo [global options] list [command options] [--flag arg] [-x arg] [tasks]
todo [global options] list [command options] [--otherflag arg] [-b] [-f|--foobar] contexts
todo [global options] list [command options] [tasks] [--flag arg] [-x arg]
todo [global options] list [command options] contexts [--otherflag arg] [-b] [-f|--foobar]
DESCRIPTION
List a whole lot of things that you might be keeping track of in your
Expand Down Expand Up @@ -198,8 +198,8 @@ Feature: The todo app has a nice user interface
list - List things, such as tasks or contexts
SYNOPSIS
todo [global options] list [command options] [--flag arg] [-x arg] [tasks]
todo [global options] list [command options] [--otherflag arg] [-b] [-f|--foobar] contexts
todo [global options] list [command options] [tasks] [--flag arg] [-x arg]
todo [global options] list [command options] contexts [--otherflag arg] [-b] [-f|--foobar]
DESCRIPTION
List a whole lot of things that you might be keeping track of in your overall todo list. This is your go-to place or finding all of the things that you might have stored in your todo databases.
Expand All @@ -221,8 +221,8 @@ Feature: The todo app has a nice user interface
list - List things, such as tasks or contexts
SYNOPSIS
todo [global options] list [command options] [--flag arg] [-x arg] [tasks]
todo [global options] list [command options] [--otherflag arg] [-b] [-f|--foobar] contexts
todo [global options] list [command options] [tasks] [--flag arg] [-x arg]
todo [global options] list [command options] contexts [--otherflag arg] [-b] [-f|--foobar]
DESCRIPTION
Expand Down Expand Up @@ -252,8 +252,8 @@ Feature: The todo app has a nice user interface
list - List things, such as tasks or contexts
SYNOPSIS
todo [global options] list [command options] [--flag arg] [-x arg] [tasks]
todo [global options] list [command options] [--otherflag arg] [-b] [-f|--foobar] contexts
todo [global options] list [command options] [tasks] [--flag arg] [-x arg]
todo [global options] list [command options] contexts [--otherflag arg] [-b] [-f|--foobar]
DESCRIPTION
List a whole lot of things that you might be keeping track of in your overall todo list. This is your go-to place or finding all of the things that you might have stored in your todo databases.
Expand All @@ -275,7 +275,7 @@ Feature: The todo app has a nice user interface
SYNOPSIS
todo [global options] list tasks [command options]
todo [global options] list tasks [command options] open
todo [global options] list tasks [command options] open
DESCRIPTION
Lists all of your tasks that you have, in varying orders, and all that
Expand All @@ -299,8 +299,8 @@ Feature: The todo app has a nice user interface
SYNOPSIS
todo [global options] create
todo [global options] create contexts [context_name]
todo [global options] create tasks task_name[, task_name]*
todo [global options] create contexts [context_name]
todo [global options] create tasks task_name[, task_name]*
COMMANDS
<default> - Makes a new task
Expand Down Expand Up @@ -351,8 +351,8 @@ Feature: The todo app has a nice user interface
ls - LS things, such as tasks or contexts
SYNOPSIS
todo [global options] ls [command options] [-b] [-f|--foobar] contexts
todo [global options] ls [command options] [-x arg] tasks
todo [global options] ls [command options] contexts [-b] [-f|--foobar]
todo [global options] ls [command options] tasks [-x arg]
DESCRIPTION
List a whole lot of things that you might be keeping track of in your
Expand Down Expand Up @@ -411,3 +411,30 @@ Feature: The todo app has a nice user interface
And a config file that specifies defaults for some commands with subcommands
When I successfully run `todo help list contexts`
Then I should see the defaults for 'list contexts' from the config file in the help

# Scenario: A complex SYNOPSIS section gets summarized
# Given my terminal is only 50 characters wide
# When I successfully run `todo <help_invocation>`
# Then the output should contain:
# """
# NAME
# list - List things, such as tasks or contexts
#
# SYNOPSIS
# todo [global options] list [command options] [tasks] [--flag arg] [-x arg]
# todo [global options] list [command options] contexts [--otherflag arg] [-b] [-f|--foobar]
#
# DESCRIPTION
# List a whole lot of things that you might be keeping track of in your
# overall todo list.
#
# This is your go-to place or finding all of the things that you might have
# stored in your todo databases.
#
# COMMAND OPTIONS
# -l, --[no-]long - Show long form
#
# COMMANDS
# contexts - List contexts
# tasks - List tasks (default)
# """
14 changes: 7 additions & 7 deletions features/todo_legacy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Feature: The todo app is backwards compatible with legacy subcommand parsing
list - List things, such as tasks or contexts
SYNOPSIS
todo [global options] list [command options] [--flag arg] [-x arg] [tasks]
todo [global options] list [command options] [--otherflag arg] [-b] [-f|--foobar] contexts
todo [global options] list [command options] [tasks] [--flag arg] [-x arg]
todo [global options] list [command options] contexts [--otherflag arg] [-b] [-f|--foobar]
DESCRIPTION
List a whole lot of things that you might be keeping track of in your
Expand Down Expand Up @@ -65,7 +65,7 @@ Feature: The todo app is backwards compatible with legacy subcommand parsing
SYNOPSIS
todo [global options] list tasks [command options]
todo [global options] list tasks [command options] open
todo [global options] list tasks [command options] open
DESCRIPTION
Lists all of your tasks that you have, in varying orders, and all that
Expand All @@ -89,8 +89,8 @@ Feature: The todo app is backwards compatible with legacy subcommand parsing
SYNOPSIS
todo [global options] create
todo [global options] create contexts [context_name]
todo [global options] create tasks task_name[, task_name]*
todo [global options] create contexts [context_name]
todo [global options] create tasks task_name[, task_name]*
COMMANDS
<default> - Makes a new task
Expand All @@ -109,8 +109,8 @@ Feature: The todo app is backwards compatible with legacy subcommand parsing
ls - LS things, such as tasks or contexts
SYNOPSIS
todo [global options] ls [command options] [-b] [-f|--foobar] contexts
todo [global options] ls [command options] [-x arg] tasks
todo [global options] ls [command options] contexts [-b] [-f|--foobar]
todo [global options] ls [command options] tasks [-x arg]
DESCRIPTION
List a whole lot of things that you might be keeping track of in your
Expand Down
21 changes: 14 additions & 7 deletions lib/gli/commands/help_modules/command_help_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,25 @@ def command_with_subcommand_usage(sub,is_default_command)
else
sub.flags.merge(sub.switches)
end
usage << sub_options.map { |option_name,option|
option.names_and_aliases.map { |_|
CommandLineOption.name_as_string(_,false) + (option.kind_of?(Flag) ? " #{option.argument_name }" : '')
}.join('|')
}.map { |_| "[#{_}]" }.sort.join(' ')
usage << ' '
if is_default_command
usage << "[#{sub.name}]"
else
usage << sub.name.to_s
end
usage << ArgNameFormatter.new.format(sub.arguments_description,sub.arguments_options)
sub_options_doc = sub_options.map { |_,option|
option.names_and_aliases.map { |name|
CommandLineOption.name_as_string(name,false) + (option.kind_of?(Flag) ? " #{option.argument_name }" : '')
}.join('|')
}.map { |invocations| "[#{invocations}]" }.sort.join(' ').strip
if sub_options_doc.length > 0
usage << ' '
usage << sub_options_doc
end
arg_name_doc = ArgNameFormatter.new.format(sub.arguments_description,sub.arguments_options).strip
if arg_name_doc.length > 0
usage << ' '
usage << arg_name_doc
end
usage
end

Expand Down

0 comments on commit 0b9f74e

Please sign in to comment.