Class: HighCarb::Command
- Inherits:
-
Object
- Object
- HighCarb::Command
- Defined in:
- lib/highcarb/command.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#command_line ⇒ Object
readonly
Returns the value of attribute command_line.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ Command
constructor
A new instance of Command.
- #parse!(args) ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
16 17 18 19 20 |
# File 'lib/highcarb/command.rb', line 16 def initialize @command_line = @args = [] @options = {} @logger = Logger.new(STDERR).tap {|logger| logger.level = Logger::WARN } end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
14 15 16 |
# File 'lib/highcarb/command.rb', line 14 def args @args end |
#command_line ⇒ Object (readonly)
Returns the value of attribute command_line.
13 14 15 |
# File 'lib/highcarb/command.rb', line 13 def command_line @command_line end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/highcarb/command.rb', line 12 def @options end |
Instance Method Details
#parse!(args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/highcarb/command.rb', line 22 def parse!(args) @command_line = args.dup @args = args @options = Trollop.(@args) do opt "generate", "Generate a new highcarb project" opt "server", "Start the servers (default action). See --http-port and --ws-port" opt "http-port", "HTTP server port", default: 9090 opt "ws-port", "WebSockets port", default: 9091 opt "skip-libs", "Don't download vendor libraries, like Deck.js and jQuery" opt "verbose", "Be verbose" opt "auth", "Require auth to access", default: "" end if @options["verbose"] @logger.level = Logger::DEBUG end self end |
#run! ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/highcarb/command.rb', line 46 def run! if args.size != 1 STDERR.puts "Please indicate the project path as an extra argument of the command. For example:" STDERR.puts "$ \033[1m#$0 #{command_line * " "} project-path/\033[m" exit 1 end if ["generate"] # Generate a new project HighCarb::Generator.new(self, args.first).run! else auth = nil if not ["auth"].empty? user, password = ["auth"].split(":", 2) if password.nil? print "Type the password for #{user}: " $stdout.flush password = $stdin.noecho { $stdin.readline.chomp } end auth = [ user, password ] end HighCarb::Services.start!(self, @logger, auth) end rescue HighCarb::Error => error STDERR.puts "ERROR: " + error. end |