Class: App

Inherits:
Object
  • Object
show all
Includes:
Help
Defined in:
lib/nu/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Help

#filter_markdown, #help_doc_for, #help_doc_path

Constructor Details

#initialize(arguments, stdin, stdout) ⇒ App

Returns a new instance of App.



18
19
20
21
22
23
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
69
70
71
72
# File 'lib/nu/app.rb', line 18

def initialize(arguments, stdin, stdout)

# Set defaults
  @options = OpenStruct.new
  @options.verbose = false
  @options.quiet = false
@commands = []    

@arguments = arguments
@help_command = lambda{output_help}

Nu::Api.set_log(lambda {|msg| log msg})
Nu::Api.set_out(lambda {|msg| disp msg})
@shim = CliShim.new(lambda {|msg| disp msg}, lambda {|msg| log msg})

#special case, they want to know our version
if arguments.length == 1 && (arguments[0] == '--version' || arguments[0] == '-v')
	@commands << lambda {output_version}
	execute_commands
	exit 0
end

begin
	OptionParser.new do |opts|

		opts.on('-v', '--version VERSION') do |ver|
			 @options.package_version = ver
		end

		opts.on('-r','--report') do
			@commands << lambda {@shim.report}
		end

		# Specify options
		@options.source = :lib
		opts.on('--remote') {@options.source = :remote}
		opts.on('--cache') {@options.source = :cache unless @options.source == :remote}
		opts.on('-V', '--verbose')    { @options.verbose = true }  
		opts.on('-q', '--quiet')      { @options.quiet = true }
		opts.on('--json') {set_json}

		opts.on_tail( '-h', '--help' ) do
			output_help
		end
	
end.parse!
	rescue
@commands << @help_command
execute_commands
exit 0
	end
	
post_process_options
extract_commands
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/nu/app.rb', line 16

def options
  @options
end

Instance Method Details

#runObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/nu/app.rb', line 74

def run
      
  if arguments_valid? 
    
    log "Start at #{DateTime.now}\n\n"
    output_inputs if @options.verbose
    
	execute_commands

    log "\nFinished at #{DateTime.now}"
    
  else
    @commands << @help_command
	execute_commands
	exit 0
  end
    
end