class CiHelper::CLI

Responsible for parsing command-line option and executing appropriate application logic based on those options

Attributes

arguments[R]
input[R]
options[R]
parser[R]

Public Class Methods

new(arguments, input) click to toggle source
# File lib/ci_helper/cli.rb, line 11
def initialize(arguments, input)
  @arguments       = arguments
  @input           = input
  @options         = {}
  options[:target] = CiHelper::Utils.repo_root
end

Public Instance Methods

run() click to toggle source
# File lib/ci_helper/cli.rb, line 18
def run
  @parser = create_option_parser
  parser.parse!(arguments)
  if initialize?
    user_setting = get_initialize_data
    Installer.new(options[:target], user_setting).install_ci_helper_config
  elsif run?
    MainProcess.new(options[:target]).run
  else
    puts parser.help
  end
end

Private Instance Methods

add_information_options(opts) click to toggle source
# File lib/ci_helper/cli.rb, line 41
def add_information_options(opts)
  opts.on('-h', '--help', 'Show this message') do
    puts opts.help
  end

  opts.on('-i', '--install', 'Install a config setting by user input') do
    @options[:action] = :install
  end

  opts.on('-r', '--run', 'run the ci helper') do
    @options[:action] = :run
  end
end
create_option_parser() click to toggle source
# File lib/ci_helper/cli.rb, line 33
def create_option_parser
  OptionParser.new do |opts|
    opts.banner = "Usage: #{opts.program_name} [options]"

    add_information_options(opts)
  end
end
get_initialize_data() click to toggle source
# File lib/ci_helper/cli.rb, line 63
def get_initialize_data
  puts 'Please input your ci server account '
  ci_account = gets.chop
  puts 'Please input your ci server password'
  ci_password = gets.chop
  puts 'Please input your bitbucket account'
  bitbucket_account = gets.chop
  puts 'Please input your bitbucket password'
  bitbucket_password = gets.chop
  puts 'Please input your redmine account'
  redmine_ac = gets.chop
  puts 'Please input your remind password'
  redmine_pass = gets.chop

  { ci:        { account: ci_account, password: ci_password },
    bitbucket: { account: bitbucket_account, password: bitbucket_password },
    redmine: { account: redmine_ac, password: redmine_pass}}
end
initialize?() click to toggle source
# File lib/ci_helper/cli.rb, line 55
def initialize?
  options[:action] == :install
end
run?() click to toggle source
# File lib/ci_helper/cli.rb, line 59
def run?
  options[:action] == :run
end