Class: Askcii::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/askcii/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV.dup) ⇒ CLI

Returns a new instance of CLI.



9
10
11
12
13
# File 'lib/askcii/cli.rb', line 9

def initialize(args = ARGV.dup)
  @args = args
  @options = {}
  @prompt = nil
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/askcii/cli.rb', line 7

def options
  @options
end

#promptObject (readonly)

Returns the value of attribute prompt.



7
8
9
# File 'lib/askcii/cli.rb', line 7

def prompt
  @prompt
end

Instance Method Details

#clear_history?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/askcii/cli.rb', line 65

def clear_history?
  @options[:clear_history]
end

#configure?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/askcii/cli.rb', line 33

def configure?
  @options[:configure]
end

#help?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/askcii/cli.rb', line 29

def help?
  @options[:help]
end

#help_messageObject



69
70
71
# File 'lib/askcii/cli.rb', line 69

def help_message
  option_parser.to_s
end

#history?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/askcii/cli.rb', line 61

def history?
  @options[:history]
end

#last_response?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/askcii/cli.rb', line 37

def last_response?
  @options[:last_response]
end

#list_sessions?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/askcii/cli.rb', line 57

def list_sessions?
  @options[:list_sessions]
end

#model_config_idObject



49
50
51
# File 'lib/askcii/cli.rb', line 49

def model_config_id
  @options[:model_config_id]
end

#parse!Object



15
16
17
18
19
# File 'lib/askcii/cli.rb', line 15

def parse!
  option_parser.parse!(@args)
  @prompt = @args.join(' ')
  self
end

#private?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/askcii/cli.rb', line 41

def private?
  @options[:private]
end

#sessionObject



53
54
55
# File 'lib/askcii/cli.rb', line 53

def session
  @options[:session]
end

#show_help?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/askcii/cli.rb', line 21

def show_help?
  @options[:help]
end

#show_usage?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/askcii/cli.rb', line 25

def show_usage?
  @prompt.empty? && !configure? && !last_response? && !list_sessions? && !history? && !clear_history?
end

#usage_messageObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/askcii/cli.rb', line 73

def usage_message
  "    Usage:\n      askcii [options] 'Your prompt here'\n      echo 'Your prompt here' | askcii                    # Use piped text as prompt\n      echo 'Context text' | askcii 'Your prompt here'     # Use piped text as context\n      askcii 'Your prompt here' < prompt.txt              # Use file content as context\n      cat prompt.txt | askcii                             # Use file content as prompt\n      askcii -p (start a private session)\n      askcii -r (to get the last response)\n      askcii -c (manage configurations)\n      askcii -m 2 (use configuration ID 2)\n\n    Options:\n      -p, --private         Start a private session and do not record\n      -r, --last-response   Output the last response\n      -c, --configure       Manage configurations\n      -m, --model ID        Use specific configuration ID\n      -h, --help            Show help\n  USAGE\nend\n"

#verbose?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/askcii/cli.rb', line 45

def verbose?
  @options[:verbose]
end