Class: Acter::Help
- Inherits:
-
Object
- Object
- Acter::Help
- Defined in:
- lib/acter/help.rb
Instance Method Summary collapse
- #general_help ⇒ Object
- #help_for_action(action, subject) ⇒ Object
- #help_for_subject(subject) ⇒ Object
-
#initialize(schema) ⇒ Help
constructor
A new instance of Help.
Constructor Details
#initialize(schema) ⇒ Help
Returns a new instance of Help.
9 10 11 |
# File 'lib/acter/help.rb', line 9 def initialize(schema) @schema = schema end |
Instance Method Details
#general_help ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/acter/help.rb', line 13 def general_help StringIO.open do |s| s.puts "USAGE: #{Acter.program_name}#{Acter. ? " [options]" : ""} <subject> <action> <params...>" s.puts Acter. if Acter. if @schema s.puts s.puts "Perform #{@schema.description} requests defined by JSON schema" s.puts s.puts "Valid subjects:" @schema.properties.keys.sort.each do |subj| s.puts " #{subj}" end end s.string end end |
#help_for_action(action, subject) ⇒ Object
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 75 76 77 |
# File 'lib/acter/help.rb', line 47 def help_for_action(action, subject) link = @schema.properties[subject].cromulent_links.find {|li| li.title.underscore == action } StringIO.open do |s| s.puts "USAGE: #{Acter.program_name}#{Acter. ? " [options]" : ""} #{subject} #{example_command(link)}" s.puts Acter. if Acter. s.puts s.puts link.description if link.schema && link.schema.properties s.puts s.puts "Parameters:" link.schema.properties.each do |name, prop_schema| next if prop_schema.read_only? descr = nil if !prop_schema.default.nil? descr = "default #{prop_schema.default.inspect}" elsif !(ex = prop_schema.make_example).nil? descr = "e.g. #{ex.inspect}" elsif !prop_schema.enum.nil? descr = prop_schema.enum.map(&:inspect).join(", ") elsif !prop_schema.type.empty? descr = prop_schema.type.map(&:capitalize).join("|") end descr = [descr, prop_schema.description].compact.join(" - ") required = link.schema.required && link.schema.required.include?(name) ? " (REQUIRED)" : "" s.puts " #{name}#{required} : #{descr}" end end s.string end end |
#help_for_subject(subject) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/acter/help.rb', line 30 def help_for_subject(subject) prop_schema = @schema.properties[subject] StringIO.open do |s| s.puts "USAGE: #{Acter.program_name}#{Acter. ? " [options]" : ""} #{subject} <action> <params...>" s.puts Acter. if Acter. s.puts s.puts "Perform #{@schema.description} #{prop_schema.description} requests defined by JSON schema" s.puts s.puts "Valid actions:" prop_schema.cromulent_links.each do |li| s.puts " #{example_command(li)}" s.puts " #{li.description}" end s.string end end |