lib/pennyworth/cli.rb in pennyworth-0.2.0 vs lib/pennyworth/cli.rb in pennyworth-1.0.0
- old
+ new
@@ -3,12 +3,12 @@
require "thor/actions"
require "thor_plus/actions"
module Pennyworth
class CLI < Thor
- include Thor::Actions
- include ThorPlus::Actions
+ include Thor::Actions
+ include ThorPlus::Actions
# Overwrites the Thor template source root.
def self.source_root
File.expand_path File.join(File.dirname(__FILE__), "templates")
end
@@ -26,46 +26,46 @@
method_option :upcase, aliases: "-u", desc: "Upcase a string.", type: :array
method_option :capitalize, aliases: "-c", desc: "Capitalize words in a string.", type: :array
method_option :length, aliases: "-l", desc: "Answer the length of a string.", type: :array
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
+ when options[:downcase]
+ Pennyworth::Kits::String.downcase options[:downcase]
+ when options[:upcase]
+ Pennyworth::Kits::String.upcase options[:upcase]
+ when options[:capitalize]
+ Pennyworth::Kits::String.capitalize options[:capitalize]
+ when options[:length]
+ Pennyworth::Kits::String.length options[:length]
else say("Type 'pennyworth help string' for usage.")
end
end
- desc "-i, [install]", "Install Alfred Extensions."
+ desc "-i, [install]", "Install Alfred Workflows."
map "-i" => :install
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)
+ if yes? "Installing Alfred Workflows will destroy exiting workflows of the same name. Continue (y/n)?"
+ info "Installing Alfred Workflows..."
+
+ workflows = Dir.glob File.join(self.class.source_root, "workflows", "**")
+ alfred_workflows_root = File.join @settings[:alfred_settings_root], "workflows"
+ workflows.each do |workflow|
+ name = File.basename workflow
+ destination = File.join alfred_workflows_root, name
+ remove_file destination
+ directory File.join("workflows", name), destination
end
- info "Alfred Extensions installed."
+
+ info "Alfred Workflows installed."
else
- info "Alfred Extenions installation cancelled."
+ info "Alfred Workflows installation cancelled."
end
else
- error "Invalid directory for Alfred settings root: #{@settings[:alfred_settings_root]}"
+ error "Invalid Alfred settings directory: #{@settings[:alfred_settings_root]}"
end
say
end
@@ -76,10 +76,10 @@
end
desc "-v, [version]", "Show version."
map "-v" => :version
def version
- say "Pennyworth " + VERSION
+ say "Pennyworth " + VERSION
end
desc "-h, [help]", "Show this message."
def help task = nil
say and super