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

Added --summary #37

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions ok-show.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def main():
parser.add_argument('--terminal_width', '-t', metavar='TW', type=int, default=None, help='number of columns of the terminal (tput cols)')
parser.add_argument('--internal_commands', '-I', metavar='IC', type=str, default='list,list-once,list-prompt,help', help='Internal commands of ok (that cannot be used as named lines)')

parser.add_argument('command', metavar='CMD', type=str, nargs='?', help='The command name or line number to show (system commands: .list_commands)')
parser.add_argument('command', metavar='CMD', type=str, nargs='?', help='The command name or line number to show (system commands: .list_commands; .list_named_commands)')
args = parser.parse_args()

if args.terminal_width is None:
Expand Down Expand Up @@ -313,8 +313,13 @@ def main():
format_lines(p_lines, args.heading_align, args.comment_align, nr_positions_line_nr, args.terminal_width)

if system_command:
all_commands = [p_line.get_line_name_or_number() for p_line in p_lines if p_line.name is not None]
if args.command == '.list_commands':
print(' '.join([p_line.get_line_name_or_number() for p_line in p_lines if p_line.name is not None]+internal_commands))
print(' '.join(all_commands))
elif args.command in ('.list_named_commands', '.summary'):
named_commands = list(set(all_commands) - set(internal_commands))
named_commands.sort()
print(' '.join(named_commands))
else:
print('Unknown system command "{}"'.format(args.command))
sys.exit(1)
Expand Down
4 changes: 3 additions & 1 deletion ok.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ command (use one):
list-prompt Show the list and wait for input at the ok-prompt (like --list and <number> in one command).$list_prompt_default
help Show this usage page.
options:
-s, --summary Show all named commands, space seperated
-c, --comment-align N Level of comment alignment. See \$_OK_COMMENT_ALIGN
-v, --verbose Show more output, mostly errors. Also it shows environment-variables in this screen.
-q, --quiet Only show really necessary output, so surpress echoing the command.
Expand Down Expand Up @@ -156,8 +157,9 @@ environment variables (for internal use):
-f | --file) if [[ $# -gt 1 && -r "$2" || "-" == "$2" ]]; then ok_file="$2"; shift; else _ok_cmd_usage "No file provided, or file is not readable ($2)" || return $?; fi;;
-a | --alias) if [[ $# -gt 1 && -n "$2" ]]; then args="$2"; shift; else _ok_cmd_usage "Empty or no alias provided" || return $?; fi;;
#system options
-s | --summary) cmd=".list_named_commands";;
--sys-cmds) cmd=".list_commands";;
--sys-opts) cmd=noop; echo "--version --help --verbose --quiet --comment-align --file --alias";;
--sys-opts) cmd=noop; echo "--version --help --verbose --quiet --comment-align --file --alias --summary";;
-*) cmd=usage; usage_error="Illegal option '$1'";;
*) if [[ $1 =~ $re_is_cmd ]]; then
cmd=run
Expand Down