Class: Gb::Create

Inherits:
SubCommand show all
Defined in:
lib/commands/create.rb

Instance Attribute Summary

Attributes inherited from SubCommand

#gb_config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SubCommand

#check_uncommit, #run_in_config, #save_workspace_config, #workspace_config

Methods inherited from Command

#error, handle_exception, #info, report_error, run

Constructor Details

#initialize(argv) ⇒ Create

Returns a new instance of Create.



25
26
27
28
29
# File 'lib/commands/create.rb', line 25

def initialize(argv)
  @config_url = argv.option('config_url')
  @private_token = argv.option('private_token')
  super
end

Class Method Details

.optionsObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/commands/create.rb', line 14

def self.options
  options = [
      ["--config_url=[url]", "指定配置文件url地址"],
      ["--private_token=[token]", "GitLab private token"],
  ].concat(super)
  options.delete_if do |option|
    option[0] =~ /^--config=/
  end
  options
end

Instance Method Details

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/commands/create.rb', line 35

def run
  local_config_path = "./Gb.yml"
  if File.exist?(local_config_path)
    raise Error.new("'#{local_config_path}' exists.")
  end

  if @config_url.nil?
    path = File.expand_path("../../Gb.yml", File.dirname(__FILE__))
    if File.exist?(path)
      gb_config = GbConfig.load_file(path)
    else
      raise Error.new("'#{path}' not found.")
    end
  else
    yml_response = nil
    open(@config_url) do |http|
      yml_response = http.read
    end
    gb_config = GbConfig.load_yml(yml_response)
  end

  if @private_token.nil?
    begin
      print "Input GitLab private token:  "
      private_token = STDIN.gets.chomp
    end until private_token.length > 0
    @private_token = private_token
  end

  gb_config.gitlab.private_token = @private_token

  File.open("./Gb.yml", 'w') do |file|
    Psych.dump(gb_config.to_dictionary, file)
  end

end

#validate!Object



31
32
33
# File 'lib/commands/create.rb', line 31

def validate!
  super
end