Class: Gitl::Create

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

Instance Attribute Summary

Attributes inherited from SubCommand

#gitl_config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SubCommand

#check_uncommit, #run_in_workspace, #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.



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

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

Class Method Details

.optionsObject



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

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

Instance Method Details

#runObject



33
34
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
# File 'lib/commands/create.rb', line 33

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

  if @config_url.nil?
    path = File.expand_path("../../Gitl.yml", File.dirname(__FILE__))
    if File.exist?(path)
      gitl_config = GitlConfig.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
    gitl_config = GitlConfig.load_yml(yml_response)
  end

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

  gitl_config.gitlab.private_token = private_token

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

end

#validate!Object



29
30
31
# File 'lib/commands/create.rb', line 29

def validate!
  super
end