1. add default option for tool [why] the tool will show help message if no option specified
[how] if no option specified, it will add '-h' as default option
2. fix undefined method 'empty' [why] the original data is defined nil, but not empty for my_email when execute answerback-email with no -e or -f, it will throw error as: raceback (most recent call last): 2: from ./answerback-email.rb:213:in `<main>' 1: from ./answerback-email.rb:184:in `send_account' ./answerback-email.rb:155:in `check_my_email': undefined method `empty?' for nil:NilClass (NoMethodError)
[how] use '.nil?' instead of '.empty?'
Signed-off-by: Luan Shengde shdluan@163.com --- container/assign-account/answerback-email.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/container/assign-account/answerback-email.rb b/container/assign-account/answerback-email.rb index c6bfdd3..1aaad75 100755 --- a/container/assign-account/answerback-email.rb +++ b/container/assign-account/answerback-email.rb @@ -136,7 +136,10 @@ options = OptionParser.new do |opts| end end
-options.parse!(ARGV) +if ARGV.empty? + ARGV << '-h' + options.parse!(ARGV) +end
def apply_account(my_info, conf_info) apply_info = {} @@ -152,7 +155,7 @@ def check_my_email(my_info) message += "use -e to add an email address for applying account\n" message += 'or use -f to add an email file'
- raise message if my_info['my_email'].empty? + raise message if my_info['my_email'].nil? end
def build_my_info_from_input(my_info, email_info, my_info_es, stdin_info)