Signed-off-by: Hu XueJiao 1034502035@qq.com --- sbin/build-my-info.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/sbin/build-my-info.rb b/sbin/build-my-info.rb index 40193af..2562062 100755 --- a/sbin/build-my-info.rb +++ b/sbin/build-my-info.rb @@ -3,16 +3,26 @@ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
-require 'io/console' require_relative '../lib/es_client' require_relative '../lib/build_my_info_client' +require 'optparse'
-print 'email: ' -my_email = $stdin.echo = gets.chomp -print 'name: ' -my_name = $stdin.echo = gets.chomp -print 'lab: ' -lab = $stdin.echo = gets.chomp +option = {} +options= OptionParser.new do |opts| + opts.on('-e email', 'my_email') do |email| + option[:email] = email + end
-build_my_info = BuildMyInfo.new(my_email, my_name, lab) + opts.on('-n name', 'my_name') do |name| + option[:name] = name + end + + opts.on('-l lab', 'lab') do |lab| + option[:lab] = lab + end +end + +options.parse! + +build_my_info = BuildMyInfo.new(option[:my_email],option[:my_name],option[:lab]) build_my_info.config_my_info
-require 'io/console' require_relative '../lib/es_client' require_relative '../lib/build_my_info_client' +require 'optparse'
-print 'email: ' -my_email = $stdin.echo = gets.chomp -print 'name: ' -my_name = $stdin.echo = gets.chomp -print 'lab: ' -lab = $stdin.echo = gets.chomp +option = {} +options= OptionParser.new do |opts|
- opts.on('-e email', 'my_email') do |email|
- option[:email] = email
- end
-build_my_info = BuildMyInfo.new(my_email, my_name, lab)
- opts.on('-n name', 'my_name') do |name|
- option[:name] = name
- end
- opts.on('-l lab', 'lab') do |lab|
- option[:lab] = lab
- end
+end
+options.parse!
+build_my_info = BuildMyInfo.new(option[:my_email],option[:my_name],option[:lab]) build_my_info.config_my_info
you'd better add checking case lack of option -e, -n, and -l
Thanks, Luan Shengde
-- 2.23.0
-require 'io/console' require_relative '../lib/es_client' require_relative '../lib/build_my_info_client' +require 'optparse'
-print 'email: ' -my_email = $stdin.echo = gets.chomp -print 'name: ' -my_name = $stdin.echo = gets.chomp -print 'lab: ' -lab = $stdin.echo = gets.chomp +option = {} +options= OptionParser.new do |opts|
- opts.on('-e email', 'my_email') do |email|
- option[:email] = email
- end
-build_my_info = BuildMyInfo.new(my_email, my_name, lab)
- opts.on('-n name', 'my_name') do |name|
- option[:name] = name
- end
- opts.on('-l lab', 'lab') do |lab|
- option[:lab] = lab
- end
+end
+options.parse!
+build_my_info = BuildMyInfo.new(option[:my_email],option[:my_name],option[:lab])
you may also need to add helps how to use the new script for people who will use it
Thanks, Luan Shengde
build_my_info.config_my_info
2.23.0
On Tue, Jan 05, 2021 at 07:03:13PM +0800, Hu Xuejiao wrote:
Signed-off-by: Hu XueJiao 1034502035@qq.com
sbin/build-my-info.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/sbin/build-my-info.rb b/sbin/build-my-info.rb index 40193af..2562062 100755 --- a/sbin/build-my-info.rb +++ b/sbin/build-my-info.rb @@ -3,16 +3,26 @@ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
-require 'io/console' require_relative '../lib/es_client' require_relative '../lib/build_my_info_client' +require 'optparse'
-print 'email: ' -my_email = $stdin.echo = gets.chomp -print 'name: ' -my_name = $stdin.echo = gets.chomp -print 'lab: ' -lab = $stdin.echo = gets.chomp +option = {} +options= OptionParser.new do |opts|
- opts.on('-e email', 'my_email') do |email|
- option[:email] = email
- end
it's best to add option explanation, it's easier to understand. Thanks, Liushaofei
-build_my_info = BuildMyInfo.new(my_email, my_name, lab)
- opts.on('-n name', 'my_name') do |name|
- option[:name] = name
- end
- opts.on('-l lab', 'lab') do |lab|
- option[:lab] = lab
- end
+end
+options.parse!
+build_my_info = BuildMyInfo.new(option[:my_email],option[:my_name],option[:lab]) build_my_info.config_my_info -- 2.23.0