Class: ThemeJuice::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/theme-juice/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/theme-juice/cli.rb', line 6

def initialize(*)
  super

  @version = VERSION
  @env     = Env
  @io      = IO
  @config  = Config
  @project = Project
  @util    = Util.new
  @list    = Tasks::List
  @init    = Commands::Init
  @create  = Commands::Create
  @delete  = Commands::Delete
  @deploy  = Commands::Deploy
  @update  = Commands::Update

  init_env
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

For dynamic methods defined within the config



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/theme-juice/cli.rb', line 215

def method_missing(method, *args, &block)

  # Force Thor to parse options
  parser   = Thor::Options.new self.class.class_options
  @options = parser.parse args

  # Init env (again) with parsed options
  init_env

  err = -> { @io.error "Could not find command '#{method}'" }
  err.call unless @config.exist?

  if @config.commands.has_key? "#{method}"
    @config.command method.to_sym, args
  else
    err.call
  end
end

Instance Method Details

#createObject



155
156
157
158
# File 'lib/theme-juice/cli.rb', line 155

def create
  @io.hello
  @create.new(options).execute
end

#deleteObject



186
187
188
# File 'lib/theme-juice/cli.rb', line 186

def delete
  @delete.new(options).unexecute
end

#deploy(stage, *args) ⇒ Object



193
194
195
# File 'lib/theme-juice/cli.rb', line 193

def deploy(stage, *args)
  @deploy.new(options).send(stage, *args).execute
end

#envObject



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/theme-juice/cli.rb', line 113

def env
  if options[:property].nil?
    @io.list "Environment:", :green, @env.inspect
  else
    prop = options[:property].gsub "-", "_"

    @io.error "Environment property '#{prop}' does not exist",
    NotImplementedError unless @env.respond_to? prop

    @io.say @env.send(prop), :color => :green
  end
end

#help(command = nil) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/theme-juice/cli.rb', line 86

def help(command = nil)
  root = File.expand_path "../man", __FILE__
  man = ["tj", command].compact.join("-")
  begin
    man_path = "#{root}/#{man}"
    if File.exist? man_path
      shell_escaped_man_path = man_path.shellescape
      if OS.windows?
        @io.say File.read("#{shell_escaped_man_path}.txt"), :color => :white
      else
        @util.run "man #{shell_escaped_man_path}", :verbose => @env.verbose
      end
    else
      @io.say "No man page available for '#{command}'", :color => :red
    end
  rescue
    super
  end
end

#initObject



128
129
130
131
132
133
134
# File 'lib/theme-juice/cli.rb', line 128

def init
  @io.say "Initializing the VM...", {
    :color => [:black, :on_green, :bold],
    :row   => true
  }
  @init.new(options).execute
end

#listObject



198
199
200
# File 'lib/theme-juice/cli.rb', line 198

def list
  @list.new(options).list :projects
end

#setupObject



176
177
178
179
# File 'lib/theme-juice/cli.rb', line 176

def setup
  @io.hello
  @create.new(options.dup.merge(:bare => true)).execute
end

#update(*args) ⇒ Object



203
204
205
# File 'lib/theme-juice/cli.rb', line 203

def update(*args)
  @update.new(options).execute
end

#versionObject



107
108
109
# File 'lib/theme-juice/cli.rb', line 107

def version
  @io.say @version, :color => :green
end

#vm(*args) ⇒ Object



208
209
210
211
212
# File 'lib/theme-juice/cli.rb', line 208

def vm(*args)
  @util.inside @env.vm_path do
    @util.run "vagrant #{args.join(" ")}", :verbose => @env.verbose
  end
end