Class: Ore::CLI

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

Instance Method Summary collapse

Instance Method Details

#install(uri) ⇒ Object

Installs a template into ~/.ore/templates.

Parameters:

  • uri (String)

    The Git URI to install the template from.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ore/cli.rb', line 44

def install(uri)
  url = URI(uri)

  name = File.basename(url.path)
  name.gsub!(/\.git$/,'')

  path = File.join(Config::TEMPLATES_DIR,name)

  if File.directory?(path)
    say "Template #{name} already installed.", :red
    exit -1
  end

  FileUtils.mkdir_p(path)
  system('git','clone',uri,path)
end

#listObject

Lists builtin and installed templates.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ore/cli.rb', line 24

def list
  print_template = lambda { |path|
    puts "  #{File.basename(path)}"
  }

  say "Builtin templates:", :green
  Config.builtin_templates(&print_template)

  say "Installed templates:", :green
  Config.installed_templates(&print_template)
end

#remove(name) ⇒ Object

Removes a previously installed template.

Parameters:

  • name (String)

    The name of the template to remove.



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ore/cli.rb', line 82

def remove(name)
  name = File.basename(name)
  path = File.join(Config::TEMPLATES_DIR,name)

  unless File.exists?(path)
    say "Unknown template: #{name}", :red
    exit -1
  end

  FileUtils.rm_rf(path)
end

#updateObject

Updates all previously installed templates.



66
67
68
69
70
71
72
# File 'lib/ore/cli.rb', line 66

def update
  Config.installed_templates do |path|
    say "Updating #{File.basename(path)} ...", :green

    Dir.chdir(path) { system('git','pull','-q') }
  end
end

#versionObject

Prints VERSION.



99
100
101
# File 'lib/ore/cli.rb', line 99

def version
  puts "ore #{Ore::VERSION}"
end