Skip to content

Commit

Permalink
src: explore: Adding verbose mode.
Browse files Browse the repository at this point in the history
This commit adds support for the verbose parameter within `kw explore`.
The verbose parameter gives details of the commands that are executed behind the scenes.

Note: This is part of the issue: kworkflow#179

Signed-off-by: Aquila Macedo <aquilamacedo@riseup.net>
  • Loading branch information
aquilamacedo committed Apr 18, 2023
1 parent 3e8c07f commit 6be4e4f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
5 changes: 4 additions & 1 deletion documentation/man/features/explore.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kw-explore

SYNOPSIS
========
*kw* (*e* | *explore*) [(-l | \--log) | (-g | \--grep) | (-a | \--all)]
*kw* (*e* | *explore*) [(-l | \--log) | (-g | \--grep) | (-a | \--all) | (-v| \--verbose)]
[(-c | \--only-source) | (-H | \--only-header)] <expr>
[-p] [<dir> | <file>]

Expand Down Expand Up @@ -44,3 +44,6 @@ OPTIONS

-H | \--only-header:
With this option, it is possible to show only the results from the header.

-v, \--verbose:
Verbose mode allows the user to see the commands executed under the hood.
1 change: 1 addition & 0 deletions src/_kw
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ _kw_e() { _kw_explore }
_kw_explore()
{
_arguments : \
'(-v --verbose)'{-v,--verbose}'[enable verbose mode]' \
'(-l --log -g --grep -a --all)'{-l,--log}'[search based on git log]' \
'(-g --grep -l --log -a --all)'{-g,--grep}'[search for string matches using GNU grep. Also searches in .git]' \
'(-a --all -l --log -g --grep)'{-a,--all}'[search for all matches in files under or not git management]' \
Expand Down
2 changes: 1 addition & 1 deletion src/bash_autocomplete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function _kw_autocomplete()
kw_options['diff']='--no-interactive'
kw_options['df']="${kw_options['diff']}"

kw_options['explore']='--log --grep --all --only-source --only-header'
kw_options['explore']='--log --grep --all --only-source --only-header --verbose'
kw_options['e']="${kw_options['explore']}"

kw_options['init']='--arch --force --remote --target --template'
Expand Down
22 changes: 19 additions & 3 deletions src/explore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function explore_main()
search="${options_values['SEARCH']}"
path="${options_values['PATH']:-'.'}"

[[ -n "${options_values['VERBOSE']}" ]] && flag='VERBOSE'

if [[ "${options_values['SCOPE']}" == "HEADER" ]]; then
path="${path}/*.h"
elif [[ "${options_values['SCOPE']}" == "SOURCE" ]]; then
Expand Down Expand Up @@ -73,8 +75,8 @@ function explore_main()
# This function also set options_values
function parse_explore_options()
{
local long_options='log,grep,all,only-header,only-source,exactly'
local short_options='l,g,a,H,c'
local long_options='log,grep,all,only-header,only-source,exactly,verbose'
local short_options='l,g,a,H,c,v'
local options

if [[ "$#" -eq 0 ]]; then
Expand All @@ -95,6 +97,7 @@ function parse_explore_options()
options_values['TYPE']=''
options_values['SCOPE']=''
options_values['EXACTLY']=''
options_values['VERBOSE']=''

eval "set -- $options"

Expand Down Expand Up @@ -153,6 +156,10 @@ function parse_explore_options()
options_values['EXACTLY']=1
shift
;;
--verbose | -v)
options_values['VERBOSE']=1
shift
;;
--) # End of options, beginning of arguments
shift
;;
Expand Down Expand Up @@ -187,6 +194,8 @@ function explore_git_log()
local path="$2"
local flag="$3"

flag=${flag:-'SILENT'}

cmd_manager "$flag" "git log --grep='$search_string' $path"
}

Expand All @@ -202,6 +211,8 @@ function explore_files_under_git()
local path="$2"
local flag="$3"

flag=${flag:-'SILENT'}

cmd_manager "$flag" "git grep -e '$regex' -nI $path"
}

Expand All @@ -219,6 +230,8 @@ function explore_all_files_git()
local path="$2"
local flag="$3"

flag=${flag:-'SILENT'}

cmd_manager "$flag" "git grep --no-index -e '$regex' -nI $path"
}

Expand All @@ -235,6 +248,8 @@ function explore_files_gnu_grep()
local path="$2"
local flag="$3"

flag=${flag:-'SILENT'}

cmd_manager "$flag" "grep --color -nrI $path -e '$regex'"
}

Expand All @@ -251,5 +266,6 @@ function explore_help()
' explore,e --grep,-g <string> - Search for <string> using the GNU grep tool' \
' explore,e --all,-a <string> - Search for all <string> match under or not of git management' \
' explore,e --only-source,-c <string> - Search for all <string> in source files' \
' explore,e --only-header,-H <string> - Search for all <string> in header files'
' explore,e --only-header,-H <string> - Search for all <string> in header files' \
' explore,e --verbose,-v - Show a detailed output'
}

0 comments on commit 6be4e4f

Please sign in to comment.