- New =
SubCommand.new(
'new', 'Creates a new project from a template',
options_obj
) { |options, args|
parsed_options = options.parse(args)
if (!Boot::Lib::Core::SubCommand.is_flag(args[0]))
template_name = args[0]
else
puts options_obj.banner
next
end
output_path = !parsed_options[:out].nil? ? Dir.pwd + '/' + parsed_options[:out] : Dir.pwd
if (Dir.exists?(output_path) && !((Dir[output_path + "/*"]).empty?))
puts "Error: #{output_path} exists and is not empty"
next end
if (File.exists?(output_path))
puts "Error: #{output_path} exists and is a file"
next end
c = 0
while c < args.length do
break if (args[c] == '--')
c+=1
end
template_args = args[c+1..-1]
if (template_args.nil?) template_args = []
end
template = Core::Template.get_template_by_name(template_name)
if template.nil?
puts "Fatal: Could not find template #{template_name}"
exit(1)
end
puts "Creating #{output_path} based on '#{template.name}' template"
loading_thread = nil
loading_thread = Thread.new {
print "Doing stuff"
while true do
print ".."
sleep 0.3
end
}
creation_thread = Thread.new {
Thread.current.thread_variable_set("success", true);
begin
template.create(template_args, output_path)
rescue ArgumentError => e
Thread.current.thread_variable_set("success", false);
puts "\r" + e.message
end
}
creation_thread.join
loading_thread.exit
if (creation_thread.thread_variable_get("success"))
puts "\nDone!"
end
}
- Help =
SubCommand.new(
'help', 'Print the help message', options_obj, false
) do |_options, _args|
Boot.sub_commands.each do |_key, cmd|
cmd.print_help_message
end
end
- Config =
SubCommand.new(
'config', 'Read configuration options',
options_obj
) { |options, args|
parsed_options = options.parse(args);
if (!parsed_options[:all])
option_name = args[0]
option_val = Boot.config.config[option_name]
if (option_val == nil)
puts "No option '#{option_name}'"
else
puts "#{option_name} = #{option_val}"
end
else
puts JSON.pretty_generate(Boot.config.config)
end
}
- Version =
SubCommand.new(
'version', 'Print the version',
options_obj,
false
) { |options, args|
puts Boot::VERSION
}
- Template =
SubCommand.new(
'template', 'Print info for a template',
options_obj
) { |options, args|
parsed_options = options.parse(args)
if (parsed_options[:list])
templates = {}
Boot.config.templates_path.each do |dir|
Dir[dir + "/*"].each do |template_path|
name = template_path.split('/')[-1]
if (templates[name].nil?)
templates[name] = Core::Template.get_template_by_name(name)
end
end
end
templates.each do |key, value|
if (parsed_options[:verbose])
puts "key: " + key
puts "name: " + value.name
puts "location: " + value.path
puts "description:\n"
puts value.description
puts
else
puts key
end
end
next
end
if (args.length != 1)
puts "usage 'boot template [template name]'"
end
template_name = args[0]
template = Core::Template.get_template_by_name(template_name)
if (template.nil?)
puts "Could not find template '#{template_name}'"
else
msg = ''
msg << 'Template: ' + template.name + "\n"
msg << 'Description: ' + template.description + "\n"
msg << 'Location: ' + template.path + "\n"
msg << "\nOptions\n"
template.template_options.each do |key, value|
msg << key
msg << ' '
if (!value['values'].nil?)
msg << '['
value['values'].each do |key,value|
msg << "#{key}/"
end
msg = msg[0..-2] msg << "]\n"
elsif(!value['symbol'].nil?)
msg << value['symbol']
msg << "\n"
else
fail if (value['files'].nil?) msg << "\n"
end
msg << "\t" + value['description']
msg << "\n\n"
end
puts msg
end
}