Skip to content

Commit

Permalink
src: mail: Adding verbose mode.
Browse files Browse the repository at this point in the history
This commit adds support for the verbose parameter within `kw mail`.
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 27, 2023
1 parent d908143 commit 8fa1f1c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
7 changes: 7 additions & 0 deletions documentation/man/features/mail.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ SYNOPSIS
| *kw mail* (-l | \--list)
| *kw mail* \--verify [\--local | \--global]
| *kw mail* \--template[=<template>] [-n | \--no-interactive] [\--local | \--global] [-f | \--force] [(<config> <value>)...]
| *kw mail* \--verbose

DESCRIPTION
===========
Expand Down Expand Up @@ -116,6 +118,11 @@ OPTIONS
-l, \--list:
Lists the settings that mail uses.

\--verbose:
Verbose mode is an option that causes the kw program to display debug messages to track
its progress. This functionality is very useful during the debugging process, allowing
you to identify possible errors more easily.

EXAMPLES
========
If you wish to use gmail you can run the following command to setup all the
Expand Down
1 change: 1 addition & 0 deletions src/_kw
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ _kw_mail()
fi

_arguments : \
'(--verbose)--verbose[enable verbose mode]' \
'(-s --send -t --setup -i --interactive -l --list --verify --template)'{-s,--send}'[send a patch by email using git send-email]' \
'(-t --setup -s --send -i --interactive -l --list --verify --template)'{-t,--setup}'[initialize and configure mail functionality]' \
'(-i --interactive -s --send -t --setup -l --list --verify --template)'{-i,--interactive}'[interactively prompt the user for the values of the options]' \
Expand Down
2 changes: 1 addition & 1 deletion src/bash_autocomplete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function _kw_autocomplete()
kw_options['mail']='--setup --local --global --force --verify --list --email
--name --smtpuser --smtpencryption --smtpserver
--smtpserverport --smtppass --template --interactive
--no-interactive --send --to --cc --simulate --private'
--no-interactive --send --to --cc --simulate --private --verbose'

kw_options['maintainers']='--authors --update-patch'
kw_options['m']="${kw_options['mantainers']}"
Expand Down
22 changes: 17 additions & 5 deletions src/mail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ declare -gr email_regex='[A-Za-z0-9_\.-]+@[A-Za-z0-9_-]+(\.[A-Za-z0-9]+)+'
#shellcheck disable=SC2119
function mail_main()
{
local flag

flag=${flag:-'SILENT'}

if [[ "$1" =~ -h|--help ]]; then
mail_help "$1"
exit 0
Expand All @@ -35,8 +39,10 @@ function mail_main()
return 22 # EINVAL
fi

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

if [[ -n "${options_values['SEND']}" ]]; then
mail_send
mail_send "$flag"
return 0
fi

Expand All @@ -59,12 +65,12 @@ function mail_main()
fi

if [[ -n "${options_values['INTERACTIVE']}" ]]; then
interactive_setup
interactive_setup "$flag"
exit
fi

if [[ "${options_values['SETUP']}" == 1 ]]; then
mail_setup
mail_setup "$flag"
exit
fi

Expand Down Expand Up @@ -912,7 +918,7 @@ function parse_mail_options()
local patch_version=''
local commit_count=''
local short_options='s,t,f,v:,i,l,n,'
local long_options='send,simulate,to:,cc:,setup,local,global,force,verify,'
local long_options='send,simulate,to:,cc:,setup,local,global,force,verify,verbose,'
long_options+='template::,interactive,no-interactive,list,private,rfc,'
local pass_option_to_send_email

Expand Down Expand Up @@ -950,6 +956,7 @@ function parse_mail_options()
options_values['RFC']=''
options_values['COMMIT_RANGE']=''
options_values['PRIVATE']=''
options_values['VERBOSE']=''

while [[ "$#" -gt 0 ]]; do
case "$1" in
Expand Down Expand Up @@ -1050,6 +1057,10 @@ function parse_mail_options()
options_values['PATCH_VERSION']="$1$2"
shift 2
;;
--verbose)
options_values['VERBOSE']=1
shift
;;
--)
shift
# if a reference is passed after the -- we need to account for it
Expand Down Expand Up @@ -1103,7 +1114,8 @@ function mail_help()
' mail (-i | --interactive) - Setup interactively' \
' mail (-l | --list) - List the configurable options' \
' mail --verify - Check if required configurations are set' \
' mail --template[=<template>] [-n] - Set send-email configs based on <template>'
' mail --template[=<template>] [-n] - Set send-email configs based on <template>' \
' mail --verbose - Show a detailed output'
}

load_mail_config
3 changes: 3 additions & 0 deletions tests/mail_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ function test_mail_parser()
parse_mail_options '--send'
assert_equals_helper 'Set send flag' "$LINENO" "${options_values['SEND']}" 1

parse_mail_options '--verbose'
assert_equals_helper 'Set verbose option' "$LINENO" "${options_values['VERBOSE']}" 1

parse_mail_options '--private'
expected='--suppress-cc=all'
assert_equals_helper 'Set private flag' "$LINENO" "${options_values['PRIVATE']}" "$expected"
Expand Down

0 comments on commit 8fa1f1c

Please sign in to comment.