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.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ore/cli.rb', line 39

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.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ore/cli.rb', line 19

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.



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ore/cli.rb', line 77

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.



61
62
63
64
65
66
67
# File 'lib/ore/cli.rb', line 61

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

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