Class: Roro::CLI

Inherits:
Thor
  • Object
show all
Includes:
FileReflection, Utilities, Thor::Actions
Defined in:
lib/roro/cli/generate/generate_containers.rb,
lib/roro.rb,
lib/roro/cli.rb,
lib/roro/cli/rollon.rb,
lib/roro/cli/generate/generate.rb,
lib/roro/cli/generate/generate_keys.rb,
lib/roro/cli/generate/generate_mise.rb,
lib/roro/cli/generate/generate_exposed.rb,
lib/roro/cli/generate/generate_harvest.rb,
lib/roro/cli/generate/generate_adventure.rb,
lib/roro/cli/generate/generate_obfuscated.rb,
lib/roro/cli/generate/generate_environments.rb,
lib/roro/cli/generate/generate_adventure_tests.rb

Overview

Where all the generation, configuration, greenfielding happens.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FileReflection

#gather_environments, #get_key, #source_files

Methods included from Utilities

#adventure_name, #all_inflections, #build_paths, #children, #file_extension, #file_name, #read_yaml, #sanitize, #sentence_from, #sort_hash_deeply, #stack_is_adventure?, #stack_is_dotfile?, #stack_is_empty?, #stack_is_file?, #stack_is_ignored?, #stack_is_inflection?, #stack_is_inflection_stub?, #stack_is_itinerary_path?, #stack_is_nil?, #stack_is_node?, #stack_is_parent?, #stack_is_stack?, #stack_is_story?, #stack_is_story_path?, #stack_is_storyfile?, #stack_is_templates?, #stack_name, #stack_not_present?, #stack_parent, #stack_parent_path, #stack_stories, #stack_type, #stack_unpermitted?, #story_is_empty?, #story_name, #story_paths

Class Method Details

.catalog_rootObject



31
32
33
# File 'lib/roro/cli.rb', line 31

def self.catalog_root
  "#{File.dirname(__FILE__)}/stacks/catalog/unstoppable/developer_styles"
end

.dependency_rootObject



27
28
29
# File 'lib/roro/cli.rb', line 27

def self.dependency_root
  "#{roro_root}/dependencies"
end

.miseObject



45
46
47
# File 'lib/roro/cli.rb', line 45

def self.mise
  mise_location.split("#{Dir.pwd}/").last
end

.mise_locationObject



35
36
37
38
39
40
41
42
43
# File 'lib/roro/cli.rb', line 35

def self.mise_location
  lookup = Dir.glob("#{Dir.pwd}/**/*.roro")&.first&.split("#{Dir.pwd}/")
  mise = if lookup
           lookup.last.split('/').first
         else
           'roro'
         end
  "#{Dir.pwd}/#{mise}"
end

.roro_default_containersObject



57
58
59
# File 'lib/roro/cli.rb', line 57

def self.roro_default_containers
  %w[backend database frontend]
end

.roro_environmentsObject



49
50
51
# File 'lib/roro/cli.rb', line 49

def self.roro_environments
  %w[base development production test staging ci]
end

.roro_rootObject



23
24
25
# File 'lib/roro/cli.rb', line 23

def self.roro_root
  "#{File.dirname(__FILE__)}"
end

.source_rootObject



19
20
21
# File 'lib/roro/cli.rb', line 19

def self.source_root
  "#{@template_root || File.dirname(__FILE__)}/templates"
end

.stack_documentation_rootObject



53
54
55
# File 'lib/roro/cli.rb', line 53

def self.stack_documentation_root
  '<a href="url">link text</a>'
end

.stacksObject



15
16
17
# File 'lib/roro/cli.rb', line 15

def self.stacks
  "#{File.dirname(__FILE__)}/stacks"
end

.supported_rubiesObject



7
8
9
# File 'lib/roro/cli.rb', line 7

def self.supported_rubies
  %w[3.0 2.7 2.6 2.5]
end

.test_rootObject



11
12
13
# File 'lib/roro/cli.rb', line 11

def self.test_root
  "#{ENV['PWD']}/test"
end

Instance Method Details

#generateObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/roro/cli/generate/generate.rb', line 35

def generate
  order = %w[mise_en_place containers environments keys]
  order.each do |item|
    value = options[item]
    case item
    when 'mise_en_place'
      generate_mise(value)
    when 'containers'
      generate_containers(*value)
    when 'environments'
      generate_environments(*value)
    when 'keys'
      generate_keys(*value)
    end
  end
end

#generate_adventure(adventure) ⇒ Object



10
11
12
13
14
15
# File 'lib/roro/cli/generate/generate_adventure.rb', line 10

def generate_adventure(adventure)
  @env = { adventure_name: adventure.split('/').last }
  location = "lib/roro/stacks/#{adventure}"
  directory 'adventure', location, @env
  generate_adventure_tests
end

#generate_adventure_tests(kase = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/roro/cli/generate/generate_adventure_tests.rb', line 10

def generate_adventure_tests(kase = nil)
  reflector = Roro::Configurators::Reflector.new
  itineraries = reflector.itineraries

  kases = kase ? [kase] : reflector.cases
  kases.each_with_index do |choice, index|
    @env = { adventure_title: itineraries[index].join(' & ') }
    location = "test/roro/stacks/#{choice.join('/')}"
    directory 'adventure_test', location, @env
  end
end

#generate_containers(*containers) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/roro/cli/generate/generate_containers.rb', line 9

def generate_containers(*containers)
  mise = Roro::CLI.mise
  containers = options['containers'] || (containers.empty? ? %w[frontend backend database] : containers)
  create_file("#{mise}/scripts/.keep")

  containers.each { |s| s.split('/').last }.each do |container|
    create_file("#{mise}/containers/#{container}/scripts/.keep")
    create_file("#{mise}/containers/#{container}/env/.keep")
  end
end

#generate_environments(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/roro/cli/generate/generate_environments.rb', line 8

def generate_environments(*args)
  if args.last.is_a?(Hash)
    hash = args.pop
  end
  default_environments = Roro::CLI.roro_environments
  mise = Roro::CLI.mise
  environments = args.empty? ? default_environments : args
  containers = Dir.glob("./#{mise}/containers/*").select { |f| File.directory?(f) }
  create_file "./#{mise}/env/.keep", ''
  environments.each do |env|
    content = hash&.dig(env.to_sym)&.each&.map {|k,v| "#{k}=#{v[:value]}"}&.join("\n") || 'SOME_KEY=some_value'
    create_file "./#{mise}/env/#{env}.env", content
    containers.each do |container|
      create_file "#{container}/env/#{env}.env", content
    end
  end
end

#generate_exposed(*environments) ⇒ Object



6
7
8
9
# File 'lib/roro/cli/generate/generate_exposed.rb', line 6

def generate_exposed(*environments)
  exposer = Roro::Crypto::Exposer.new
  exposer.expose(environments, Roro::CLI.mise, '.env.enc')
end

#generate_harvestObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/roro/cli/generate/generate_harvest.rb', line 8

def generate_harvest
  reflector = Roro::Reflector.new
  content = {
    cases: reflector.cases.map { |c| c.join(' ') },
    structure_human: reflector.adventure_structure_human,
    structure_choices: reflector.adventure_structure_choices
    # itineraries: harvest_itineraries,
    # metadata: @reflector.metadata
  }
  content.each do |key, value|
    create_file ".harvest/#{key}.yml", value.to_yaml
  end
end

#generate_keys(*environments) ⇒ Object



10
11
12
13
# File 'lib/roro/cli/generate/generate_keys.rb', line 10

def generate_keys(*environments)
  key_writer = Roro::Crypto::KeyWriter.new
  key_writer.write_keyfiles(environments.uniq)
end

#generate_mise(mise_name = 'mise') ⇒ Object



9
10
11
# File 'lib/roro/cli/generate/generate_mise.rb', line 9

def generate_mise(mise_name = 'mise')
  create_file "#{mise_name}/#{mise_name}.roro"
end

#generate_obfuscated(*environments) ⇒ Object



9
10
11
12
# File 'lib/roro/cli/generate/generate_obfuscated.rb', line 9

def generate_obfuscated(*environments)
  obfuscator = Roro::Crypto::Obfuscator.new
  obfuscator.obfuscate(environments, Roro::CLI.mise, '.env')
end

#rollonObject



7
8
9
10
# File 'lib/roro/cli/rollon.rb', line 7

def rollon
  configurator = Roro::Configurators::Configurator.new
  configurator.rollon
end