Class: Sambot::Commands::Cookbook

Inherits:
Thor
  • Object
show all
Defined in:
lib/sambot/commands/cookbook.rb

Constant Summary collapse

Runtime =
Sambot::Domain::Common::Runtime
ApplicationError =
Sambot::Domain::Common::ApplicationError
GUIDE =
{
  clean: {
    SHORT_DESC: 'Remove all generated build files from a cookbook',
    LONG_DESC:  "    `sambot cookbook clean` will remove all files generated by `sambot cookbook build`.\n    This is required to ensure the generated files are not stored in source control.\n    LONGDESC\n  },\n  build: {\n    SHORT_DESC: 'Builds a cookbook from its configuration file',\n    LONG_DESC:  <<-LONGDESC\n    `sambot cookbook build` will generate all the files required for the functioning\n    of a Chef cookbook from a configuration file. The motivation behind this setup is to\n    standardize and simplify the Chef cookbook creation workflow. The configuration file should be\n    called .config.yml and stored in the root of the Chef cookbook.\n    LONGDESC\n  },\n  generate: {\n    SHORT_DESC: 'Creates a new cookbook',\n    LONG_DESC: <<-LONGDESC\n    `sambot cookbook generate` will create a new cookbook. This can be either a\n    wrapper cookbook or an instance role cookbook.\n    LONGDESC\n  },\n  version: {\n    SHORT_DESC: 'Gives the cookbook version as a TeamCity service message',\n    LONG_DESC: ''\n  }\n}\n"

Instance Method Summary collapse

Instance Method Details

#buildObject



56
57
58
59
60
61
# File 'lib/sambot/commands/cookbook.rb', line 56

def build
  Runtime.ensure_latest
  Domain::Cookbook.build(ESSENTIAL_FILES, GENERATED_FILES)
rescue ApplicationError => e
  error(e.message)
end

#cleanObject



47
48
49
50
51
52
# File 'lib/sambot/commands/cookbook.rb', line 47

def clean
  Runtime.ensure_latest
  Domain::Cookbook.clean(GENERATED_FILES - ['.gitignore'])
rescue ApplicationError => e
  error(e.message)
end

#generateObject



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sambot/commands/cookbook.rb', line 65

def generate()
  Runtime.ensure_latest
  name = ask(' What is the name of this cookbook?')
  description = ask(' What does this cookbook do?')
  platforms = ask(' What operating system will this cookbook run on?', :limited_to => ['windows', 'centos', 'both'])
  type = ask(' What type of cookbook will this be?', :limited_to => ['wrapper', 'role'])
  platforms = platforms == 'both' ? ['centos', 'windows'] : [platforms]
  Domain::Cookbook.generate(name, platforms, type, description, ESSENTIAL_FILES, GENERATED_FILES)
rescue ApplicationError => e
  error(e.message)
end

#versionObject



79
80
81
82
83
84
85
# File 'lib/sambot/commands/cookbook.rb', line 79

def version()
  Runtime.ensure_latest
  result = Domain::Common::Config.read
  puts "##teamcity[buildNumber '#{result['version'].to_s}']"
rescue ApplicationError => e
  error(e.message)
end