Module: Hen::Commands
Constant Summary
collapse
- COMMANDS =
{
'config' => 'Create a fresh .henrc file',
'create' => [
'Create a new project directory tree',
'Arguments: path [sample-skeleton]',
'Options: -g, --git [[remote=]url]'
],
'help' => 'Print this help and exit',
'version' => 'Display version number'
}
- USAGE =
"Usage: \#{$0} {\#{COMMANDS.keys.sort.join('|')}} [arguments] [options]\n \#{$0} [-h|--help] [--version]\n"
- SKELETON =
File.expand_path('../../../example', __FILE__)
Instance Method Summary
collapse
Methods included from CLI
classname, emailaddress, fullname, githubuser, progdesc, progname, progsumm, render
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
123
124
125
|
# File 'lib/hen/commands.rb', line 123
def method_missing(method, *)
abort "Illegal command: #{method}\n#{USAGE}"
end
|
Instance Method Details
#[](arg) ⇒ Object
62
63
64
65
|
# File 'lib/hen/commands.rb', line 62
def [](arg)
arg = arg.sub(/\A-+/, '')
arg !~ /\W/ && public_method_defined?(arg) ? send(arg) : method_missing(arg)
end
|
#config ⇒ Object
97
98
99
100
101
102
|
# File 'lib/hen/commands.rb', line 97
def config
render(File.join(SKELETON, '_henrc'), henrc = Hen.default_henrc)
puts
puts "Your .henrc has been created: #{henrc}. Now adjust it to your needs."
end
|
#create ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/hen/commands.rb', line 104
def create
abort 'Path argument missing!' unless path = ARGV.shift
skel = ARGV.first !~ /^-/ && ARGV.shift || File.join(SKELETON, 'project')
abort "Project skeleton not found: #{skel}" unless File.directory?(skel)
create_path(path = File.expand_path(path), created = [])
create_skel(path, skel = File.expand_path(skel), created, replace = {})
puts
puts "Your new project directory has been created: #{path}. Have fun!"
replace.each { |target, details|
puts ["\n#{target}:", *details].join("\n ") unless details.empty?
}.clear
end
|
#help ⇒ Object
Also known as:
h
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/hen/commands.rb', line 71
def help
puts USAGE
puts
puts 'Commands:'
max = COMMANDS.keys.max(:length)
COMMANDS.sort.each { |cmd, desc|
puts " %-#{max}s - %s" % [cmd, (desc = [*desc]).shift]
desc.each { || puts " %#{max}s + %s" % [' ', ] }
}
end
|
#list ⇒ Object
86
87
88
89
90
91
|
# File 'lib/hen/commands.rb', line 86
def list
abort 'Sorry, not yet available...'
end
|
#usage ⇒ Object
67
68
69
|
# File 'lib/hen/commands.rb', line 67
def usage
abort USAGE
end
|
#version ⇒ Object
93
94
95
|
# File 'lib/hen/commands.rb', line 93
def version
puts "hen v#{VERSION}"
end
|