[PATCH compass-ci 1/2] sbin/mail-job: add help option

[Why] It's more friendly to user that command-line tool have a help option Signed-off-by: Lu Weitao <luweitaobe@163.com> --- sbin/mail-job | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/sbin/mail-job b/sbin/mail-job index 954c149..85e37a1 100755 --- a/sbin/mail-job +++ b/sbin/mail-job @@ -3,11 +3,32 @@ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true -# Usage: -# mail-job job_id - +require 'optparse' require_relative '../lib/mail_job_result.rb' -job_id = ARGV[0] +# mail job results to job submitter +# require the job had submitted job.yaml include email + +opt_parser = OptionParser.new do |opts| + opts.banner = 'Usage: mail-job job_id' + opts.separator 'eg: mail-job crystal.123012' + opts.separator '' + opts.separator 'options:' + + opts.on_tail('-h', '--help', 'show this message') do + puts opts + exit + end +end + +argv = if ARGV == [] + ['-h'] + else + ARGV + end + +opt_parser.parse!(argv) + +job_id = argv[0] mail = MailJobResult.new(job_id) mail.send_mail -- 2.23.0

On Thu, Dec 03, 2020 at 10:26:20AM +0800, Lu Weitao wrote:
[Why] It's more friendly to user that command-line tool have a help option
Signed-off-by: Lu Weitao <luweitaobe@163.com> --- sbin/mail-job | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/sbin/mail-job b/sbin/mail-job index 954c149..85e37a1 100755 --- a/sbin/mail-job +++ b/sbin/mail-job @@ -3,11 +3,32 @@ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
-# Usage: -# mail-job job_id - +require 'optparse' require_relative '../lib/mail_job_result.rb'
Maybe it's better to use absolute paths. Thanks, Chenglong
-job_id = ARGV[0] +# mail job results to job submitter +# require the job had submitted job.yaml include email + +opt_parser = OptionParser.new do |opts| + opts.banner = 'Usage: mail-job job_id' + opts.separator 'eg: mail-job crystal.123012' + opts.separator '' + opts.separator 'options:' + + opts.on_tail('-h', '--help', 'show this message') do + puts opts + exit + end +end + +argv = if ARGV == [] + ['-h'] + else + ARGV + end + +opt_parser.parse!(argv) + +job_id = argv[0] mail = MailJobResult.new(job_id) mail.send_mail -- 2.23.0

On Thu, Dec 03, 2020 at 10:36:53AM +0800, Wang Chenglong wrote:
On Thu, Dec 03, 2020 at 10:26:20AM +0800, Lu Weitao wrote:
[Why] It's more friendly to user that command-line tool have a help option
Signed-off-by: Lu Weitao <luweitaobe@163.com> --- sbin/mail-job | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/sbin/mail-job b/sbin/mail-job index 954c149..85e37a1 100755 --- a/sbin/mail-job +++ b/sbin/mail-job @@ -3,11 +3,32 @@ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
-# Usage: -# mail-job job_id - +require 'optparse' require_relative '../lib/mail_job_result.rb'
Maybe it's better to use absolute paths.
require_relative '../lib/mail_job_result.rb' require 'ENV[CCI_SRC]/lib/mail_job_result.rb' have same effect Thanks, Weitao
Thanks, Chenglong
-job_id = ARGV[0]

On Thu, Dec 03, 2020 at 11:17:38AM +0800, Lu Weitao wrote:
On Thu, Dec 03, 2020 at 10:36:53AM +0800, Wang Chenglong wrote:
On Thu, Dec 03, 2020 at 10:26:20AM +0800, Lu Weitao wrote:
[Why] It's more friendly to user that command-line tool have a help option
Signed-off-by: Lu Weitao <luweitaobe@163.com> --- sbin/mail-job | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/sbin/mail-job b/sbin/mail-job index 954c149..85e37a1 100755 --- a/sbin/mail-job +++ b/sbin/mail-job @@ -3,11 +3,32 @@ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
-# Usage: -# mail-job job_id - +require 'optparse' require_relative '../lib/mail_job_result.rb'
Maybe it's better to use absolute paths.
require_relative '../lib/mail_job_result.rb' require 'ENV[CCI_SRC]/lib/mail_job_result.rb' have same effect
So that's it. Learning it. Thanks, Chenglong
Thanks, Weitao
Thanks, Chenglong
-job_id = ARGV[0]

On Thu, Dec 03, 2020 at 10:41:27AM +0800, Li Yuanchao wrote:
+ +argv = if ARGV == [] + ['-h'] + else + ARGV + end
You can use
argv = ARGV.empty? ? ['-h'] : ARGV
OK, let't me try Thanks, Weitao
Thanks, Yuanchao
+ +opt_parser.parse!(argv) + +job_id = argv[0] mail = MailJobResult.new(job_id) mail.send_mail -- 2.23.0
participants (3)
-
Li Yuanchao
-
Lu Weitao
-
Wang Chenglong