./bin/lux in lux-fw-0.2.3 vs ./bin/lux in lux-fw-0.5.32

- old
+ new

@@ -1,18 +1,28 @@ #!/usr/bin/env ruby +# -*- mode: ruby -*- if File.exists?('lux-fw.gemspec') puts 'Cant run in lux folder' exit end +require 'thor' require 'colorize' require 'optparse' require 'awesome_print' require 'dotenv' -module LuxCli +Dotenv.load + +LUX_ROOT = File.expand_path '../..', __FILE__ + +puts 'Lux (%s, v%s)' % [LUX_ROOT, File.read('%s/.version' % LUX_ROOT)] unless ARGV[0] + +### + +module Cli extend self def run what puts what.green system what @@ -20,78 +30,27 @@ def die text puts text.red exit end -end -Dotenv.load - -@port = 3000 -lux_root = File.expand_path '../..', __FILE__ - -if Dir.exists?('.git') - test_root = `bundle show lux-fw`.chomp - lux_root = test_root if test_root.include?('lux') + def info text + puts '* %s' % text.magenta + end end -puts 'Lux (%s, v%s)' % [lux_root, File.read('%s/.version' % lux_root)] unless ARGV[0] +### -ARGV.options do |opts| - opts.on("-e", "--environment=val", "RACK_ENV enviroment", String) do |v| - v = 'production' if v[0,1] == 'p' - v = 'development' if v[0,1] == 'd' - ENV['RACK_ENV'] = v if v - end - opts.on("-p", "--port=val", "port (3000)", String) do |v| - @port = v.to_i - end - opts.on("-f", "--flags=val", "CRSL", String) do |v| - @flags = v - end -end.parse! +trap("SIGINT") { Cli.die 'ctrl+c exit' } -commands = {} -commands['am'] = 'auto migrate' -commands['assets'] = 'precompile assets and genereate mainifest.json' -commands['console'] = 'Lux console' -commands['dev'] = 'dev on port 3000 with hot reload on code change' -commands['eval'] = 'eval code or file' -commands['exceptions'] = 'show stored exceptions, last created first' -commands['generate'] = 'generates models and views based on templates' -commands['get'] = 'get local URL' -commands['nginx'] = 'parse and install config/nginx.conf' -commands['production'] = 'run puma in production mode' -commands['routes'] = 'list routes' -commands['render'] = 'render single page' -commands['server'] = 'run puma development server' -commands['systemd'] = 'parse and install config/systemd.conf' -commands['stat'] = 'goaccess stat to public/goaccess.html' -# commands['job_que'] = 'process job que with loaded enviroment' +LuxCli = Class.new Thor -command = ARGV.shift +Dir['%s/bin/cli/*.rb' % LUX_ROOT].each { |it| load it } -if command - for c in commands - command = c[0] if c[0] if c[0].start_with?(command) - end +LuxCli.start ARGV - if commands[command] - path = '%s/bin/cli/%s' % [lux_root, command] - load path - else - LuxCli.die "Can't find command [%s]" % command - end -else - puts "\nCommands:" - for c in commands - # puts " #{c[0].sub(/(\w)/,'[\\1]').ljust(15)} # #{c[1]}" - puts " #{c[0].ljust(15)} # #{c[1]}" - end +rakes = Dir['./Rakefile*'] + Dir['./rakefile*'] - puts "\nExamples:" - puts ' lux c # lux console' - puts ' lux g user # lux generate user users' - puts '' - exit +if !ARGV[0] && rakes[0] + puts 'Or use one of rake tasks' + puts ' ' + `rake -T`.gsub($/, "\n ") end -