class Locomotive::Wagon::CLI::Main
Public Instance Methods
auth(email = nil, password = nil, platform_url = nil)
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 226 def auth(email = nil, password = nil, platform_url = nil) say "Locomotive Sign in/up\n\n", :bold platform_url ||= ask("Enter the URL of your platform? (default: #{Locomotive::Wagon::DEFAULT_PLATFORM_URL})") platform_url = Locomotive::Wagon::DEFAULT_PLATFORM_URL if platform_url.strip == '' while email.to_s.strip == ''; email = ask('Enter your e-mail?'); end while password.to_s.strip == ''; password = ask('Enter your password?', echo: false); end Locomotive::Wagon.authenticate(platform_url, email, password, shell) end
backup(name, host, path = '.')
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 266 def backup(name, host, path = '.') begin if Locomotive::Wagon.clone(name, path, { host: host }.merge(options), shell) self.print_next_instructions_when_site_created(name, path, false) end rescue Exception => e self.print_exception(e, options[:verbose]) exit(1) end end
delete(env, resource, slug = nil, path = '.')
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 399 def delete(env, resource, slug = nil, path = '.') if ask('Are you sure?', limited_to: %w(yes no)) == 'yes' Locomotive::Wagon.delete(env, path, resource, slug, shell) else say 'The delete operation has been cancelled', :red exit(1) end end
deploy(env, path = '.')
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 347 def deploy(env, path = '.') force_color_if_asked(options) if check_path!(path) begin Locomotive::Wagon.push(env, path, options, options[:shell] ? shell : nil) rescue Exception => e self.print_exception(e, options[:verbose]) exit(1) end end end
init(name, path = '.', *generator_options)
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 240 def init(name, path = '.', *generator_options) force_color_if_asked(options) require 'locomotive/wagon/generators/site' require File.expand_path(options[:lib]) if options[:lib] generator = Locomotive::Wagon::Generators::Site.get(:blank) if generator.nil? say "Unknown site template '#{options[:template]}'", :red exit(1) else begin if Locomotive::Wagon.init(generator.klass, [name, path, *generator_options], { force_color: options[:force_color] }) self.print_next_instructions_when_site_created(name, path) end rescue GeneratorException => e self.print_exception(e, options[:verbose]) exit(1) end end end
list_templates()
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 290 def list_templates force_color_if_asked(options) require 'locomotive/wagon/generators/site' require File.expand_path(options[:lib]) if options[:lib] if Locomotive::Wagon::Generators::Site.empty? say 'No templates', :red elsif !options[:json] Locomotive::Wagon::Generators::Site.list.each do |info| say info.name, :bold, false say " - #{info.description}" unless info.description.blank? end else say Locomotive::Wagon::Generators::Site.list_to_json end end
pull(env, path = '.')
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 377 def pull(env, path = '.') if check_path!(path) begin Locomotive::Wagon.pull(env, path, options, shell) rescue Exception => e self.print_exception(e, options[:verbose]) exit(1) end end end
serve(path = '.')
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 315 def serve(path = '.') force_color_if_asked(options) if check_path!(path) begin Locomotive::Wagon.serve(path, options, shell) rescue Exception => e self.print_exception(e, options[:verbose]) exit(1) end end end
stop(path = '.')
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 328 def stop(path = '.') force_color_if_asked(options) if check_path!(path) begin Locomotive::Wagon.stop(path, false, shell) rescue Exception => e say e.message, :red exit(1) end end end
sync(env, path = '.')
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 363 def sync(env, path = '.') if check_path!(path) begin Locomotive::Wagon.sync(env, path, options, shell) rescue Exception => e self.print_exception(e, options[:verbose]) exit(1) end end end
version()
click to toggle source
# File lib/locomotive/wagon/cli.rb, line 220 def version require 'locomotive/wagon/version' say Locomotive::Wagon::VERSION end
Protected Instance Methods
print_exception(exception, verbose)
click to toggle source
Print the exception.
@param [ Object ] exception The raised exception @param [ Boolean ] verbose Print the full backtrace if true
# File lib/locomotive/wagon/cli.rb, line 439 def print_exception(exception, verbose) if verbose say "\n# Error description:", :bold say exception.message, :red say "\n# Backtrace:", :bold say "\n\t" + exception.backtrace.join("\n\t") else say "\n\nError(s) found. Please use the -v option to display the full exception", :red end end
print_next_instructions_when_site_created(name, path, assets = true)
click to toggle source
Print a nice message when a site has been created.
@param [ String ] name The name of the site @param [ String ] path The path of the local site @param [ Boolean ] assets True (default) if we want to display the instructions about Webpack
# File lib/locomotive/wagon/cli.rb, line 419 def print_next_instructions_when_site_created(name, path, assets = true) say "\nCongratulations, your site \"#{name}\" has been created successfully !", :green say "\nNext steps:\n", :bold say "\n# Run the local web server", :on_blue say "\n\tcd #{path}/#{name}" say "\twagon serve" if assets say "\n# Compile assets (in a another terminal, use tmux for instance)", :on_blue say "\n\tyarn" say "\tyarn start" end say "\n# Preview your site!", :on_blue say "\n\topen http://0.0.0.0:3333\n\n", :bold end