Class: SwarmCLI::Options
- Inherits:
-
Object
- Object
- SwarmCLI::Options
- Includes:
- TTY::Option
- Defined in:
- lib/swarm_cli/options.rb
Instance Method Summary collapse
-
#config_file ⇒ Object
Convenience accessors that delegate to params.
- #has_prompt_source? ⇒ Boolean
- #initial_message ⇒ Object
- #interactive_mode? ⇒ Boolean
- #non_interactive_mode? ⇒ Boolean
- #output_format ⇒ Object
- #prompt_text ⇒ Object
- #quiet? ⇒ Boolean
- #truncate? ⇒ Boolean
- #validate! ⇒ Object
- #verbose? ⇒ Boolean
Instance Method Details
#config_file ⇒ Object
Convenience accessors that delegate to params
131 132 133 |
# File 'lib/swarm_cli/options.rb', line 131 def config_file params[:config_file] end |
#has_prompt_source? ⇒ Boolean
126 127 128 |
# File 'lib/swarm_cli/options.rb', line 126 def has_prompt_source? (params[:prompt_text] && !params[:prompt_text].empty?) || !$stdin.tty? end |
#initial_message ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/swarm_cli/options.rb', line 102 def # For REPL mode - get initial message from argument or stdin (if piped) return unless interactive_mode? if params[:prompt_text] && !params[:prompt_text].empty? params[:prompt_text] elsif !$stdin.tty? $stdin.read.strip end end |
#interactive_mode? ⇒ Boolean
92 93 94 95 |
# File 'lib/swarm_cli/options.rb', line 92 def interactive_mode? # Interactive (REPL) mode when -p flag is NOT present !params[:prompt] end |
#non_interactive_mode? ⇒ Boolean
97 98 99 100 |
# File 'lib/swarm_cli/options.rb', line 97 def non_interactive_mode? # Non-interactive mode when -p flag IS present params[:prompt] == true end |
#output_format ⇒ Object
135 136 137 |
# File 'lib/swarm_cli/options.rb', line 135 def output_format params[:output_format] end |
#prompt_text ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/swarm_cli/options.rb', line 113 def prompt_text # For non-interactive mode - get prompt from argument or stdin raise SwarmCLI::ExecutionError, "Cannot get prompt_text in interactive mode" if interactive_mode? @prompt_text ||= if params[:prompt_text] && !params[:prompt_text].empty? params[:prompt_text] elsif !$stdin.tty? $stdin.read.strip else raise SwarmCLI::ExecutionError, "No prompt provided" end end |
#quiet? ⇒ Boolean
139 140 141 |
# File 'lib/swarm_cli/options.rb', line 139 def quiet? params[:quiet] end |
#truncate? ⇒ Boolean
143 144 145 |
# File 'lib/swarm_cli/options.rb', line 143 def truncate? params[:truncate] end |
#validate! ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/swarm_cli/options.rb', line 69 def validate! errors = [] # Config file must exist if config_file && !File.exist?(config_file) errors << "Configuration file not found: #{config_file}" end # Interactive mode cannot be used with JSON output if interactive_mode? && output_format == "json" errors << "Interactive mode is not compatible with --output-format json" end # Non-interactive mode requires a prompt if non_interactive_mode? && !has_prompt_source? errors << "Non-interactive mode (-p) requires a prompt (provide as argument or via stdin)" end unless errors.empty? raise SwarmCLI::ExecutionError, errors.join("\n") end end |
#verbose? ⇒ Boolean
147 148 149 |
# File 'lib/swarm_cli/options.rb', line 147 def verbose? params[:verbose] end |