Class: Battlestation::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/battlestation/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



5
6
7
8
9
10
11
12
13
# File 'lib/battlestation/cli.rb', line 5

def initialize(*)
  super

  the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
  Battlestation.ui = UI::Shell.new(the_shell)

  Battlestation.ui.info("Manning battlestation...")
  Battlestation.ui.info("")
end

Instance Method Details

#checkObject



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
# File 'lib/battlestation/cli.rb', line 29

def check
  plan = nil
  filenames = ["Battlestation", "Battlestation.rb"].select { |f| File.exists?(f) }

  case filenames.size
  when 0
    Battlestation.ui.error "Could not read your Battlestation file"
    exit 1
  when 1
    plan = Battlestation.load(filenames.first)
    exit 1 if plan.nil?
  else # >1
    Battlestation.ui.error "You cannot have both Battlestation and Battlestation.rb files. Choose one, remove the other."
    exit 1
  end

  # Execute tasks in order
  plan.tasks.each_pair do |name, task|
    Battlestation.ui.group task.title do
      # Show a notice for empty tasks
      if task.operations.empty?
        Battlestation.ui.notice("Nothing defined for #{task.name}")
      end

      task.execute
    end
  end
end

#helpObject



20
21
22
# File 'lib/battlestation/cli.rb', line 20

def help
  Battlestation.ui.info "Create 'Battlestatio'n in the root of your project and run 'battlestation check'"
end