added a customize command to generate a template in the home directory

This commit is contained in:
Adam Sanderson 2010-11-14 15:42:06 -08:00
parent a341390510
commit 57157b5c6b
3 changed files with 17 additions and 4 deletions

14
bin/qw
View File

@ -33,8 +33,18 @@ opts = OptionParser.new do |opts|
exit(0) exit(0)
end end
opts.on("--customize", "Create files for customizing Qwandry") do opts.on("--customize", "Create and edit files for customizing Qwandry") do
dir = ENV['HOME'] && ENV['HOME'] + '/.qwandry/'
if !dir
puts "Home directory must be defined."
exit(1)
else
FileUtils.mkdir(dir, :verbose=>true) unless File.exist?(dir)
Dir[File.dirname(__FILE__) + '/../templates/*'].each do |path|
FileUtils.cp(path, dir, :verbose=>true, :preserve=>true)
end
@qwandry.launch dir
end
exit(0) exit(0)
end end

View File

@ -1,6 +1,7 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'optparse' require 'optparse'
require 'set' require 'set'
require 'fileutils'
# Informal Spec: # Informal Spec:
# #

View File

@ -49,10 +49,12 @@ module Qwandry
packages packages
end end
# Launches a `package`. Unless `editor` will check against the environment by default. # Launches a Package or path represented by a String. Unless `editor` will
# check against the environment by default.
def launch(package, editor=nil) def launch(package, editor=nil)
editor ||= @editor || ENV['VISUAL'] || ENV['EDITOR'] editor ||= @editor || ENV['VISUAL'] || ENV['EDITOR']
system editor, *package.paths paths = package.is_a?(String) ? [package] : package.paths
system editor, *paths
end end
private private