Skip to content

Commit

Permalink
Improve man and shell completion for tools (#15082)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacksmoke16 authored Oct 15, 2024
1 parent 9f3dba5 commit 5fd469c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
2 changes: 1 addition & 1 deletion etc/completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ _crystal()
_crystal_compgen_options "${opts}" "${cur}"
else
if [[ "${prev}" == "tool" ]] ; then
local subcommands="context dependencies flags format hierarchy implementations types"
local subcommands="context dependencies expand flags format hierarchy implementations types unreachable"
_crystal_compgen_options "${subcommands}" "${cur}"
else
_crystal_compgen_sources "${cur}"
Expand Down
17 changes: 16 additions & 1 deletion etc/completion.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set -l crystal_commands init build clear_cache docs env eval i interactive play run spec tool help version
set -l tool_subcommands context expand flags format hierarchy implementations types
set -l tool_subcommands context dependencies expand flags format hierarchy implementations types unreachable

complete -c crystal -s h -l help -d "Show help" -x

Expand Down Expand Up @@ -206,6 +206,21 @@ complete -c crystal -n "__fish_seen_subcommand_from implementations" -s p -l pro
complete -c crystal -n "__fish_seen_subcommand_from implementations" -s t -l time -d "Enable execution time output"
complete -c crystal -n "__fish_seen_subcommand_from implementations" -l stdin-filename -d "Source file name to be read from STDIN"

complete -c crystal -n "__fish_seen_subcommand_from tool; and not __fish_seen_subcommand_from $tool_subcommands" -a "unreachable" -d "show methods that are never called" -x
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -s D -l define -d "Define a compile-time flag"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -s f -l format -d "Output format text (default), json, csv, codecov" -a "text json csv codecov" -f
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -l tallies -d "Print reachable methods and their call counts as well"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -l check -d "Exits with error if there is any unreachable code"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -l error-trace -d "Show full error trace"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -s i -l include -d "Include path"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -s e -l exclude -d "Exclude path (default: lib)"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -l no-color -d "Disable colored output"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -l prelude -d "Use given file as prelude"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -s s -l stats -d "Enable statistics output"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -s p -l progress -d "Enable progress output"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -s t -l time -d "Enable execution time output"
complete -c crystal -n "__fish_seen_subcommand_from unreachable" -l stdin-filename -d "Source file name to be read from STDIN"

complete -c crystal -n "__fish_seen_subcommand_from tool; and not __fish_seen_subcommand_from $tool_subcommands" -a "types" -d "show type of main variables" -x
complete -c crystal -n "__fish_seen_subcommand_from types" -s D -l define -d "Define a compile-time flag"
complete -c crystal -n "__fish_seen_subcommand_from types" -s f -l format -d "Output format text (default) or json" -a "text json" -f
Expand Down
38 changes: 33 additions & 5 deletions etc/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ local -a exec_args; exec_args=(
'(\*)'{-D+,--define=}'[define a compile-time flag]:' \
'(--error-trace)--error-trace[show full error trace]' \
'(-s --stats)'{-s,--stats}'[enable statistics output]' \
'(-t --time)'{-t,--time}'[enable execution time output]'
'(-t --time)'{-t,--time}'[enable execution time output]' \
'(-p --progress)'{-p,--progress}'[enable progress output]'
)

local -a format_args; format_args=(
Expand All @@ -61,11 +62,15 @@ local -a cursor_args; cursor_args=(
'(-c --cursor)'{-c,--cursor}'[cursor location with LOC as path/to/file.cr:line:column]:LOC'
)

local -a include_exclude_args; cursor_args=(
local -a include_exclude_args; include_exclude_args=(
'(-i --include)'{-i,--include}'[Include path in output]' \
'(-i --exclude)'{-i,--exclude}'[Exclude path in output]'
)

local -a stdin_filename_args; stdin_filename_args=(
'(--stdin-filename)--stdin-filename[source file name to be read from STDIN]'
)

local -a programfile; programfile='*:Crystal File:_files -g "*.cr(.)"'

# TODO make 'emit' allow completion with more than one
Expand Down Expand Up @@ -170,6 +175,7 @@ _crystal-tool() {
"hierarchy:show type hierarchy"
"implementations:show implementations for given call in location"
"types:show type of main variables"
"unreachable:show methods that are never called"
)

_describe -t commands 'Crystal tool command' commands
Expand All @@ -187,6 +193,7 @@ _crystal-tool() {
$exec_args \
$format_args \
$prelude_args \
$stdin_filename_args \
$cursor_args
;;

Expand All @@ -198,6 +205,7 @@ _crystal-tool() {
$exec_args \
'(-f --format)'{-f,--format}'[output format 'tree' (default), 'flat', 'dot', or 'mermaid']:' \
$prelude_args \
$stdin_filename_args \
$include_exclude_args
;;

Expand All @@ -209,12 +217,14 @@ _crystal-tool() {
$exec_args \
$format_args \
$prelude_args \
$stdin_filename_args \
$cursor_args
;;

(flags)
_arguments \
$programfile \
$no_color_args \
$help_args
;;

Expand All @@ -223,8 +233,9 @@ _crystal-tool() {
$programfile \
$help_args \
$no_color_args \
$format_args \
$include_exclude_args \
'(--check)--check[checks that formatting code produces no changes]' \
'(--show-backtrace)--show-backtrace[show backtrace on a bug (used only for debugging)]'
;;

(hierarchy)
Expand All @@ -235,6 +246,7 @@ _crystal-tool() {
$exec_args \
$format_args \
$prelude_args \
$stdin_filename_args \
'(-e)-e[filter types by NAME regex]:'
;;

Expand All @@ -246,7 +258,22 @@ _crystal-tool() {
$exec_args \
$format_args \
$prelude_args \
$cursor_args
$cursor_args \
$stdin_filename_args
;;

(unreachable)
_arguments \
$programfile \
$help_args \
$no_color_args \
$exec_args \
$include_exclude_args \
'(-f --format)'{-f,--format}'[output format: text (default), json, csv, codecov]:' \
$prelude_args \
'(--check)--check[exits with error if there is any unreachable code]' \
'(--tallies)--tallies[print reachable methods and their call counts as well]' \
$stdin_filename_args
;;

(types)
Expand All @@ -256,7 +283,8 @@ _crystal-tool() {
$no_color_args \
$exec_args \
$format_args \
$prelude_args
$prelude_args \
$stdin_filename_args
;;
esac
;;
Expand Down
4 changes: 2 additions & 2 deletions man/crystal.1
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ Disable colored output.
.Op --
.Op arguments
.Pp
Run a tool. The available tools are: context, dependencies, flags, format, hierarchy, implementations, and types.
Run a tool. The available tools are: context, dependencies, expand, flags, format, hierarchy, implementations, types, and unreachable.
.Pp
Tools:
.Bl -tag -offset indent
Expand Down Expand Up @@ -442,7 +442,7 @@ Options:
.It Fl D Ar FLAG, Fl -define= Ar FLAG
Define a compile-time flag. This is useful to conditionally define types, methods, or commands based on flags available at compile time. The default flags are from the target triple given with --target-triple or the hosts default, if none is given.
.It Fl f Ar FORMAT, Fl -format= Ar FORMAT
Output format 'text' (default), 'json', or 'csv'.
Output format 'text' (default), 'json', 'codecov', or 'csv'.
.It Fl -tallies
Print reachable methods and their call counts as well.
.It Fl -check
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class Crystal::Command
Tool:
context show context for given location
dependencies show file dependency tree
expand show macro expansion for given location
flags print all macro `flag?` values
format format project, directories and/or files
hierarchy show type hierarchy
dependencies show file dependency tree
implementations show implementations for given call in location
unreachable show methods that are never called
types show type of main variables
unreachable show methods that are never called
--help, -h show this help
USAGE

Expand Down

0 comments on commit 5fd469c

Please sign in to comment.