Class: Stratus::CLI
- Inherits:
-
Object
- Object
- Stratus::CLI
- Defined in:
- lib/stratus/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#app ⇒ Object
Return the Rake application object.
- #capture_command_line_args(args) ⇒ Object
- #import_default_tasks ⇒ Object
- #import_website_tasks ⇒ Object
-
#init(args) ⇒ Object
Initialize the Rake application object and load the core rake tasks, the site specific rake tasks, and the site specific ruby code.
-
#initialize(out) ⇒ CLI
constructor
A new instance of CLI.
-
#options ⇒ Object
Returns the options hash from the Rake application object.
-
#parse(args) ⇒ Object
Parse the command line args for options and commands to invoke.
-
#rake ⇒ Object
Execute the rake command.
- #require_lib_files ⇒ Object
- #run(args) ⇒ Object
Constructor Details
#initialize(out) ⇒ CLI
Returns a new instance of CLI.
11 12 13 14 |
# File 'lib/stratus/cli.rb', line 11 def initialize(out) @out = out @mode = :site end |
Class Method Details
.run(args, out = STDOUT) ⇒ Object
140 141 142 |
# File 'lib/stratus/cli.rb', line 140 def run(args, out=STDOUT) self.new(out).run(args) end |
Instance Method Details
#app ⇒ Object
Return the Rake application object.
107 108 109 |
# File 'lib/stratus/cli.rb', line 107 def app Rake.application end |
#capture_command_line_args(args) ⇒ Object
133 134 135 136 137 |
# File 'lib/stratus/cli.rb', line 133 def capture_command_line_args(args) ::Stratus.args = args # set the args in a place where all rake tasks can read 'em ::Stratus.site_path = File.('.') args end |
#import_default_tasks ⇒ Object
117 118 119 120 121 |
# File 'lib/stratus/cli.rb', line 117 def import_default_tasks path = (@mode == :app)? %w(stratus tasks app *.rake) : %w(stratus tasks site *.rake) Dir.glob(::Stratus.libpath(path)).sort.each {|fn| load fn} Dir.glob(::Stratus.libpath(%w(stratus tasks shared *.rake))).sort.each {|fn| load fn} end |
#import_website_tasks ⇒ Object
123 124 125 126 |
# File 'lib/stratus/cli.rb', line 123 def import_website_tasks return if (@mode == :app) Dir.glob(::File.join(%w[tasks *.rake])).sort.each {|fn| load fn} end |
#init(args) ⇒ Object
Initialize the Rake application object and load the core rake tasks, the site specific rake tasks, and the site specific ruby code. Any extra command line arguments are converted into a page name and directory that might get created (depending upon the task invoked).
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/stratus/cli.rb', line 74 def init( args ) # Make sure we're in a folder with a Sitefile = app. [['--rakefile', 'StratusSite'], ['--no-search', nil], ['--silent', nil]].each {|opt, value| .assoc(opt).last.call(value)} unless app.have_rakefile @mode = :app end import_default_tasks import_website_tasks require_lib_files capture_command_line_args(args) # if args.length == 0 && @mode == :app # puts "Try using:\n stratus -T" # end args end |
#options ⇒ Object
Returns the options hash from the Rake application object.
113 114 115 |
# File 'lib/stratus/cli.rb', line 113 def app. end |
#parse(args) ⇒ Object
Parse the command line args for options and commands to invoke.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/stratus/cli.rb', line 24 def parse( args ) opts = OptionParser.new opts. = 'Usage: stratus [options] target [target args]' opts.separator '' desired_opts = %[--describe --prereqs --tasks --trace] app..each do || next unless desired_opts.include?(.first) opts.on(*) end opts.separator '' opts.separator 'common options:' opts.on_tail( '-h', '--help', 'show this message' ) do @out.puts opts exit end opts.on_tail( '-q', '--quiet', 'show compact messages' ) do ENV['STRATUS_LOGGING'] = 'quiet' end opts.on_tail( '--version', 'show version' ) do @out.puts "Stratus #{::Stratus::VERSION}" exit end begin opts.parse! args rescue OptionParser::InvalidOption => ex puts "!! #{ex}" end ARGV.replace Array(args.shift) args.delete_if do |arg| if %r/^[A-Z_]+=/ =~ arg ARGV << arg next true end false end args end |
#rake ⇒ Object
Execute the rake command.
99 100 101 102 103 |
# File 'lib/stratus/cli.rb', line 99 def rake app.init 'stratus' app.load_rakefile app.top_level end |
#require_lib_files ⇒ Object
128 129 130 131 |
# File 'lib/stratus/cli.rb', line 128 def require_lib_files return if (@mode == :app) Dir.glob(::File.join(%w[lib ** *.rb])).sort.each {|fn| require fn} end |
#run(args) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/stratus/cli.rb', line 16 def run(args) args = args.dup parse args init args rake end |