Class: ADN::CLI
- Inherits:
-
Object
- Object
- ADN::CLI
- Defined in:
- lib/adn/cli.rb,
lib/adn/cli/version.rb,
lib/adn/cli/global_stream.rb,
lib/adn/cli/unified_stream.rb,
lib/adn/cli/terminal_stream.rb
Defined Under Namespace
Classes: GlobalStream, TerminalStream, UnifiedStream
Constant Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #send_post(text) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/adn/cli.rb', line 24 def initialize if STDIN.tty? if ["-u", "--unified"].include?(ARGV.first) UnifiedStream.start elsif ["-g", "--global"].include?(ARGV.first) || ARGV.empty? GlobalStream.start else puts "Unknown parameters: #{ARGV.inspect}" end else send_post $stdin.read.strip end end |
Class Method Details
.run ⇒ Object
18 19 20 21 22 |
# File 'lib/adn/cli.rb', line 18 def self.run ADN::Auth.retrieve_token unless ADN::Auth.has_token? ADN.token = ADN::Auth.token new end |
Instance Method Details
#send_post(text) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/adn/cli.rb', line 38 def send_post(text) if text.length > 256 abort ANSI.color(:red) { "Sorry, max 256 chars" } end data = { text: text } OptionParser.new do |opts| opts.on("-r ID") { |id| data[:reply_to] = id } end.parse! ADN::Post.send_post data rescue OptionParser::ParseError => e abort "Error: #{e}" end |