Class: Pennyworth::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ CLI

Initialize.



17
18
19
20
21
# File 'lib/pennyworth/cli.rb', line 17

def initialize args = [], options = {}, config = {}
  super args, options, config
  @settings_file = File.join ENV["HOME"], ".pennyworth", "settings.yml"
  @settings = load_yaml @settings_file
end

Class Method Details

.source_rootObject

Overwrites the Thor template source root.



12
13
14
# File 'lib/pennyworth/cli.rb', line 12

def self.source_root
  File.expand_path File.join(File.dirname(__FILE__), "templates")
end

Instance Method Details

#editObject



74
75
76
# File 'lib/pennyworth/cli.rb', line 74

def edit
  `$EDITOR #{@settings_file}`
end

#help(task = nil) ⇒ Object



85
86
87
# File 'lib/pennyworth/cli.rb', line 85

def help task = nil
  say and super
end

#installObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pennyworth/cli.rb', line 51

def install
  say
  
  if valid_file?(@settings[:alfred_settings_root], "Invalid directory for Alfred settings root")
    if yes? "Installing Alfred Extensions will destroy exiting extensions of the same name. Continue (y/n)?"
      info "Installing Alfred Extensions..."
      info "Alfred settings root: #{@settings[:alfred_settings_root]}"
      %w(files scripts).each do |folder|
        directory File.join("alfred", "extensions", folder), File.join(@settings[:alfred_settings_root], "extensions", folder)
      end
      info "Alfred Extensions installed."
    else
      info "Alfred Extenions installation cancelled."
    end
  else
    error "Invalid directory for Alfred settings root: #{@settings[:alfred_settings_root]}"
  end

  say
end

#stringObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pennyworth/cli.rb', line 29

def string
  case
  when options[:downcase] then
    string = Pennyworth::Kit.array_to_string options[:downcase]
    puts Pennyworth::Kit.clip(string.downcase)
  when options[:upcase] then
    string = Pennyworth::Kit.array_to_string options[:upcase]
    puts Pennyworth::Kit.clip(string.upcase)
  when options[:capitalize] then
    words = options[:capitalize].map {|word| word.capitalize}
    words = Pennyworth::Kit.array_to_string words
    puts Pennyworth::Kit.clip(words)
  when options[:length] then
    string = Pennyworth::Kit.array_to_string options[:length]
    Pennyworth::Kit.clip(string)
    puts string.length
  else say("Type 'pennyworth help string' for usage.")
  end
end

#versionObject



80
81
82
# File 'lib/pennyworth/cli.rb', line 80

def version
	say "Pennyworth " + VERSION
end