add output usage add option -h|--help set default option to -h|--help if no options added
Signed-off-by: Luan Shengde shdluan@163.com --- sbin/build-my-info.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/sbin/build-my-info.rb b/sbin/build-my-info.rb index fd75f51..028fbac 100755 --- a/sbin/build-my-info.rb +++ b/sbin/build-my-info.rb @@ -14,6 +14,11 @@ option = { }
options = OptionParser.new do |opts| + opts.banner = "Usage: ./build-my-info.rb -e email -n name -l lab\n" + + opts.separator '' + opts.separator 'options:' + opts.on('-e email', 'my_email') do |email| option[:my_email] = email end @@ -25,8 +30,15 @@ options = OptionParser.new do |opts| opts.on('-l lab', 'lab') do |lab| option[:lab] = lab end + + opts.on_tail('-h', '--help', 'show this message') do + puts opts + exit + end end
+ARGV << '-h' if ARGV.empty? + options.parse!
build_my_info = BuildMyInfo.new(option[:my_email], option[:my_name], option[:lab])
On Thu, Jan 28, 2021 at 04:21:01PM +0800, Luan Shengde wrote:
add output usage add option -h|--help set default option to -h|--help if no options added
Signed-off-by: Luan Shengde shdluan@163.com
sbin/build-my-info.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/sbin/build-my-info.rb b/sbin/build-my-info.rb index fd75f51..028fbac 100755 --- a/sbin/build-my-info.rb +++ b/sbin/build-my-info.rb @@ -14,6 +14,11 @@ option = { }
options = OptionParser.new do |opts|
- opts.banner = "Usage: ./build-my-info.rb -e email -n name -l lab\n"
./build-my-info.rb => build-my-info and we can add #!/usr/bin/env ruby at 1st line of the file the file name can: build-my-info.rb => build-my-info
Thanks, Weitao
options = OptionParser.new do |opts|
- opts.banner = "Usage: ./build-my-info.rb -e email -n name -l lab\n"
./build-my-info.rb => build-my-info
just keep it as you actually wrote it.
Thanks, Luan Shengde
and we can add #!/usr/bin/env ruby at 1st line of the file the file name can: build-my-info.rb => build-my-info
Thanks, Weitao
options = OptionParser.new do |opts|
- opts.banner = "Usage: ./build-my-info.rb -e email -n name -l lab\n"
./build-my-info.rb => build-my-info and we can add #!/usr/bin/env ruby at 1st line of the file the file name can: build-my-info.rb => build-my-info
ok its path was added to var $PATH I see
Thanks Luan Shengde
Thanks, Weitao