Class: Chef::Knife::StashProjectCreate

Inherits:
Chef::Knife show all
Includes:
StashBase
Defined in:
lib/chef/knife/stash_project_create.rb

Instance Method Summary collapse

Methods included from StashBase

#display_stash_error, #get_all_values, #get_config, #get_repo_https_url, #get_repo_ssh_url, #get_stash_connection, included

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
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
66
# File 'lib/chef/knife/stash_project_create.rb', line 22

def run
  $stdout.sync = true
  
  key = name_args.first

  if key.nil?
    ui.fatal "You need a project key!"
    show_usage
    exit 1
  end

  name = name_args[1]

  if name.nil?
    ui.fatal "You need a project name!"
    show_usage
    exit 1
  end

  args = name_args[2]
  if args.nil?
    args = ""
  end

  stash = get_stash_connection
  project = { :name => name, :key => key }
  project[:description] = get_config(:description) if get_config(:description)

  if get_config(:noop)
    ui.info "#{ui.color "Skipping project creation process because --noop specified.", :red}"
  else
    response = stash.post do |post|
      post.url "projects"
      post.headers['Content-Type'] = "application/json"
      post.body = JSON.generate(project)
    end
    if response.success?
      ui.info "Created Stash Project: #{key} (#{name})"
    else
      display_stash_error "Could not create Stash project!", response
      exit 1
    end
  end
  
end