Class: Halation::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/halation/script.rb

Overview

The script that runs when the halation binary is executed.

Class Method Summary collapse

Class Method Details

.generate_new_rollObject

Generate a new roll.yml file. Copies “~/.halation/templates/roll.yml” if it exists, otherwise it uses a default template.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/halation/script.rb', line 85

def self.generate_new_roll
  roll_path = "roll.yml"

  if File.exists?(roll_path)
    output_stream.puts "A roll.yml file already exists in this directory."
    return
  end

  # TODO: Make this configurable from config.yml
  roll_template_path = File.expand_path("~/.halation/templates/roll.yml")

  if File.exists?(roll_template_path)
    FileUtils.cp(roll_template_path, ".")
  else
    File.open(roll_path, "w") do |f|
      f.puts new_roll_content
    end
  end
end

.run(opts = {}) ⇒ Object

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :args (Boolean) — default: ARGV
  • :output_stream (Boolean) — default: STDOUT
  • :skip_exit (Boolean) — default: false

    Don’t exit the program after calling a handler that would normally exit. Used for unit testing.



16
17
18
19
20
21
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/halation/script.rb', line 16

def self.run(opts = {})
  args = opts[:args] || ARGV
  output_stream = opts[:output_stream] || STDOUT
  skip_exit = !!opts[:skip_exit]
  run_engine = true

  options = {}

  OptionParser.new { |opts|
    opts.banner = "Usage: halation [options]"

    opts.on("-c", "--config=PATH", String, "Config file path") do |config_path|
      options[:config_path] = config_path
    end

    opts.on("--dry", "Dry run") do
      options[:dry_run] = true
      # TODO: Implement
      raise NotImplementedError, "Dry run option is not yet implemented."
    end

    opts.on("-h", "--help", "Print this help") do
      output_stream.puts opts
      run_engine = false
      exit unless skip_exit
    end

    opts.on("--new-config", "Generate a new config file") do |path|
      # TODO: Implement
      raise NotImplementedError, "Generate config option is not yet implemented."
      run_engine = false
      exit unless skip_exit
    end

    opts.on("--new-roll", "Generate a new roll.yml file") do
      generate_new_roll
      run_engine = false
      exit unless skip_exit
    end

    opts.on("-p", "--print-config", "Print the configuration settings") do
      # TODO: Implement
      raise NotImplementedError, "Print config option is not yet implemented."
      run_engine = false
      exit unless skip_exit
    end

    opts.on("-r", "--recursive", "Traverse into subdirectories") do
      # TODO: Implement
      raise NotImplementedError, "Recursive option is not yet implemented."
    end

    opts.on("--silent", "Suppress messages to stdout.") do
      options[:silent] = true
    end

    opts.on("-v", "--version", "Print the version information") do
      output_stream.puts "halation #{Halation::VERSION}"
      run_engine = false
      exit unless skip_exit
    end
  }.parse!(args)
  
  Halation::Engine.run(options) if run_engine
end