Class: Jenkins::Builder::CLI
- Inherits:
-
Thor
- Object
- Thor
- Jenkins::Builder::CLI
- Defined in:
- lib/jenkins/builder/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #alias(name = nil, command = nil) ⇒ Object
- #build(*jobs) ⇒ Object
- #info ⇒ Object
- #refresh_jobs_cache ⇒ Object
- #setup ⇒ Object
- #unalias(name) ⇒ Object
- #version ⇒ Object
Class Method Details
.create_alias_commands(aliases) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/jenkins/builder/cli.rb', line 16 def create_alias_commands(aliases) 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 |
.main(args) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/jenkins/builder/cli.rb', line 10 def main(args) validate_fzf! @config = Jenkins::Builder::Config.new create_alias_commands(@config.aliases || []) start(args) end |
.validate_fzf! ⇒ Object
25 26 27 28 29 |
# File 'lib/jenkins/builder/cli.rb', line 25 def validate_fzf! `fzf --version` rescue Errno::ENOENT raise 'Required command fzf is not installed.' end |
Instance Method Details
#alias(name = nil, command = nil) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/jenkins/builder/cli.rb', line 92 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, command) end |
#build(*jobs) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jenkins/builder/cli.rb', line 61 def build(*jobs) if [:version] puts Jenkins::Builder::VERSION exit end if .service.nil? service = fzf(Config.new().services).first exit if service.nil? else service = .service end app = Jenkins::Builder::App.new(service, ) if jobs.empty? jobs = fzf(app.fetch_all_jobs) exit if jobs.empty? job = jobs.first if app.use_mbranch?(job) branches = fzf(app.all_branches) exit if branches.empty? branch = branches.first jobs = [format('%s:%s', job, branch)] else jobs = [job] end end puts "Jobs: #{jobs.join(", ")}" app.build_each(jobs) end |
#info ⇒ Object
53 54 55 |
# File 'lib/jenkins/builder/cli.rb', line 53 def info Jenkins::Builder::App.new.print_info() end |
#refresh_jobs_cache ⇒ Object
106 107 108 |
# File 'lib/jenkins/builder/cli.rb', line 106 def refresh_jobs_cache Jenkins::Builder::App.new.refresh_jobs_cache end |
#setup ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jenkins/builder/cli.rb', line 37 def setup if [:edit] editor = ENV['VISUAL'] || ENV['EDITOR'] || "vim" exec("#{editor} #{File.('~/.jenkins-builder.yaml')}") else url = read_text('Input Jenkins URL: ') username = read_text('Input Username: ') password = read_password('Input Password: ') git_branches = read_text('Input Git Branches separated by comma, e.g. origin/develop,origin/master: ').split(/\s*,\s*/) Jenkins::Builder::App.new.setup(url: url, username: username, password: password, branches: git_branches) end end |
#unalias(name) ⇒ Object
101 102 103 |
# File 'lib/jenkins/builder/cli.rb', line 101 def unalias(name) Jenkins::Builder::App.new.delete_alias(name) end |