Class: SetupScriptGenerator::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/setup_script_generator/cli.rb

Defined Under Namespace

Classes: Provision

Constant Summary collapse

TEMPLATES_DIR =
Pathname.new("./templates").expand_path(__dir__)
PROVISIONS_DIR =
TEMPLATES_DIR.join("provisions")
SKELETON_TEMPLATE_PATH =
TEMPLATES_DIR.join("skeleton.sh.erb")
CUSTOMIZABLE_SECTION_PATH =
TEMPLATES_DIR.join("customizable-section.sh")
NON_CUSTOMIZABLE_SECTION_PATH =
TEMPLATES_DIR.join("non-customizable-section.sh.erb")
NON_CUSTOMIZABLE_SECTION_MARKER =
<<-MARKER.strip
### DON'T MODIFY ANYTHING BELOW THIS LINE! #####################################
MARKER

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, stdout, stderr) ⇒ Cli

Returns a new instance of Cli.



22
23
24
25
26
27
28
29
# File 'lib/setup_script_generator/cli.rb', line 22

def initialize(args, stdout, stderr)
  @args = args
  @stdout = stdout
  @stderr = stderr

  @provision_names = []
  @dry_run = false
end

Class Method Details

.call(args, stdout, stderr) ⇒ Object



18
19
20
# File 'lib/setup_script_generator/cli.rb', line 18

def self.call(args, stdout, stderr)
  new(args, stdout, stderr).call
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/setup_script_generator/cli.rb', line 31

def call
  parse_args!(args)
  validate_provision_names!

  if dry_run?
    stdout.puts generated_content
  else
    output_file.parent.mkpath
    output_file.write(generated_content)
    output_file.chmod(0744)
    stdout.puts "File written to: #{output_file}"
  end
end