Class: Shift::CLI
- Inherits:
-
Object
- Object
- Shift::CLI
- Defined in:
- lib/shift/cli.rb
Overview
The shifter command line interface.
Constant Summary collapse
- USAGE =
"Usage: shifter <file> [action] [format]\n" + "In pipe: shifter - format [action]\n\n" + "Available formats and actions:\n\n" + Shift.inspect_actions
Class Method Summary collapse
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(path, a = nil, b = nil) ⇒ CLI
constructor
A new instance of CLI.
- #run! ⇒ Object
- #stdin? ⇒ Boolean
Constructor Details
#initialize(path, a = nil, b = nil) ⇒ CLI
Returns a new instance of CLI.
24 25 26 27 28 29 |
# File 'lib/shift/cli.rb', line 24 def initialize(path, a=nil, b=nil) @path = path @format, @action = stdin? ? [a,b] : [b,a] @format ||= :echo @action ||= :default end |
Class Method Details
.new ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/shift/cli.rb', line 16 def self.new begin super(*ARGV) rescue ArgumentError abort USAGE end end |
Instance Method Details
#data ⇒ Object
35 36 37 |
# File 'lib/shift/cli.rb', line 35 def data stdin? ? STDIN.read : File.read(@path) end |
#run! ⇒ Object
39 40 41 |
# File 'lib/shift/cli.rb', line 39 def run! puts Shift(data, @format).process(@action) end |
#stdin? ⇒ Boolean
31 32 33 |
# File 'lib/shift/cli.rb', line 31 def stdin? @path == '-' end |