lib/jenkins/builder/cli.rb in jenkins-builder-0.1.0 vs lib/jenkins/builder/cli.rb in jenkins-builder-0.1.1

- old
+ new

@@ -1,25 +1,26 @@ require 'thor' require 'io/console' +require 'shellwords' module Jenkins module Builder class CLI < ::Thor class << self def create_alias_commands(aliases) - aliases.each do |name, job| - desc "#{name}", "alias for: #{job}" - define_method name do - Jenkins::Builder::App.new.build(job) + aliases.each do |name, command| + desc "#{name}", "alias for: #{command}" + define_method name do |*args| + self.class.start(Shellwords.split(command) + args) end end end end desc 'setup [-e]', 'Setup URL, username and password, or open config file in an editor when -e specified.' - option :edit, type: :boolean, aliases: ['-e'] + option :edit, type: :boolean, aliases: ['-e'], desc: 'open config file in an editor' def setup if options[:edit] editor = ENV['VISUAL'] || ENV['EDITOR'] || "vim" exec("#{editor} #{File.expand_path('~/.jenkins-builder.yaml')}") else @@ -31,19 +32,20 @@ Jenkins::Builder::App.new.setup(url: url, username: username, password: password, branches: git_branches) end end desc 'info [-p]', 'Show saved URL, username, use -p to show password also.' - option :password, type: :boolean, aliases: ['-p'] + option :password, type: :boolean, aliases: ['-p'], desc: 'show password also.' def info Jenkins::Builder::App.new.print_info(options) end - desc 'build [-s] <JOB_IDENTIFIERS>', 'Build jobs' - option :silent, type: :boolean, aliases: ['-s'] + desc 'build [-s] [-f] <JOB_IDENTIFIERS>', 'Build jobs' + option :silent, type: :boolean, aliases: ['-s'], desc: 'suppress console output.' + option :failfast, type: :boolean, aliases: ['-f'], desc: 'stop immediately when building fails.' def build(*jobs) - app = Jenkins::Builder::App.new(silent: options[:silent]) + app = Jenkins::Builder::App.new(options) if jobs.empty? jobs = fzf(app.all_jobs) exit if jobs.empty? job = jobs.first @@ -58,16 +60,16 @@ end puts "Jobs: #{jobs.join(", ")}" app.build_each(jobs) end - desc 'alias <ALIAS> <JOB_IDENTIFIER>', 'Create job alias' - def alias(name=nil, job=nil) - if name.nil? || job.nil? + desc 'alias <ALIAS> <COMMAND>', 'Create alias or with no arguments given, it print all aliases.' + def alias(name=nil, command=nil) + if name.nil? || command.nil? Jenkins::Builder::App.new.list_aliases exit end - Jenkins::Builder::App.new.create_alias(name, job) + Jenkins::Builder::App.new.create_alias(name, command) end desc 'unalias <ALIAS>', 'Delete alias' def unalias(name) Jenkins::Builder::App.new.delete_alias(name)