cli_tools 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +30 -6
- data/examples/ex-ansi.rb +10 -0
- data/examples/ex-block.rb +27 -0
- data/examples/ex-err.rb +11 -0
- data/examples/ex-kb-getkey.rb +11 -0
- data/examples/ex-ok.rb +3 -0
- data/examples/ex-putr.rb +12 -0
- data/examples/ex-puts-vs-putr.rb +7 -0
- data/examples/ex-raise.rb +12 -0
- data/examples/ex-sh.rb +25 -0
- data/lib/cli_tools/version.rb +1 -1
- metadata +10 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bcdce3da1ebb50323e0a4d23d8215aab5cf1036
|
4
|
+
data.tar.gz: 3967d3fb79f35e92060e6ae0b3f2beddf18d092f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec2399a559e4486599225e35e998ef22363389a44970c316d920eef1dbc0c638aa5f1deb8a6b20d1d43580f249117b4f2351ff768e0ecc35a67020bdf3f79aa3
|
7
|
+
data.tar.gz: a55b1636c974b0f289af86e20be1bdf3ba164f602a2b4548eebd30333156ee938f30403a042fb325754a507d004e9c94bb4102e8d7d48fcf0a20aa11e887bc95
|
data/README.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
-
# Tools for CLI application
|
1
|
+
# Tools for a CLI application
|
2
2
|
|
3
|
-
A collection of helper methods for ruby CLI
|
3
|
+
A collection of helper methods for ruby CLI applications.
|
4
|
+
|
5
|
+
- `sh` — shell command execution, with output capturing
|
6
|
+
- `putr` — like `puts`, but erases current line and does not advance to a new line, invaluable for displaying things like progress bar
|
7
|
+
- `esc_...` — ANSI colors for your output
|
8
|
+
- `kb_getkey` — get the f.. key pressed in a non-blocking way
|
9
|
+
- and other little friends
|
10
|
+
|
11
|
+
## Requirements
|
12
|
+
|
13
|
+
You probably need a Unix based system to find this gem useful. The gem methods are tested and working on Mac OS X and Linux systems, and it is not guaranteed to work on Windows (especially because the console input/output is done the unix way).
|
4
14
|
|
5
15
|
## Installation
|
6
16
|
|
@@ -18,21 +28,35 @@ Or install it yourself as:
|
|
18
28
|
|
19
29
|
## Usage
|
20
30
|
|
31
|
+
Keep all helper methods in CliTools namespace:
|
21
32
|
```ruby
|
22
33
|
require 'cli_tools'
|
23
|
-
include CliTools
|
24
34
|
|
25
|
-
puts esc_green("Hello")+' world!' # outputs 'Hello world!' where 'Hello' is painted green
|
35
|
+
puts CliTools.esc_green("Hello")+' world!' # outputs 'Hello world!' where 'Hello' is painted green
|
26
36
|
```
|
27
37
|
|
28
|
-
OR: all the methods automatically included
|
38
|
+
OR: have all the methods automatically included:
|
29
39
|
|
30
40
|
```ruby
|
31
|
-
require 'cli_tools/include'
|
41
|
+
require 'cli_tools/include' # equivalent to:
|
42
|
+
# require 'cli_tools'
|
43
|
+
# include CliTools
|
32
44
|
|
33
45
|
puts esc_green("Hello")+' world!'
|
34
46
|
```
|
35
47
|
|
48
|
+
### Try it out
|
49
|
+
```
|
50
|
+
cd examples/
|
51
|
+
ruby ex-ansi.rb
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
## TODO
|
56
|
+
- add more specs
|
57
|
+
- write comprehensive docs
|
58
|
+
|
59
|
+
|
36
60
|
## Contributing
|
37
61
|
|
38
62
|
1. Fork it
|
data/examples/ex-ansi.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'cli_tools/include'
|
2
|
+
|
3
|
+
out = ''
|
4
|
+
out_nest = ''
|
5
|
+
sh_capture_output( out ) do
|
6
|
+
sh "ls -la"
|
7
|
+
puts ""
|
8
|
+
puts "captured inside:"
|
9
|
+
out1 = ''
|
10
|
+
sh "ruby ex-ok.rb", true, out1
|
11
|
+
puts "out1: #{out1}"
|
12
|
+
|
13
|
+
puts "nested block:"
|
14
|
+
sh_capture_output( out_nest ) do
|
15
|
+
sh "ruby ex-err.rb" rescue puts esc_red "sh raised an exception, recovered"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
puts
|
21
|
+
puts "Globally captured output:"
|
22
|
+
puts out
|
23
|
+
|
24
|
+
puts
|
25
|
+
puts "Nested captured output:"
|
26
|
+
puts out_nest
|
27
|
+
|
data/examples/ex-err.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'cli_tools/include'
|
2
|
+
|
3
|
+
count = 0
|
4
|
+
puts "Press any key when you've had enough"
|
5
|
+
while (key = kb_getkey).nil?
|
6
|
+
count += 1
|
7
|
+
putr "#{count} #{esc_green 'bottles'} hanging on the wall... "
|
8
|
+
sleep 1
|
9
|
+
end
|
10
|
+
puts # advances to a new line
|
11
|
+
puts "pressed key code is: #{key[0].ord}"
|
data/examples/ex-ok.rb
ADDED
data/examples/ex-putr.rb
ADDED
data/examples/ex-sh.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'cli_tools/include'
|
2
|
+
|
3
|
+
if ARGV.size == 0
|
4
|
+
puts "Usage: #{__FILE__} <command> [arg1] [arg2] ..."
|
5
|
+
puts "Examples:"
|
6
|
+
puts " #{__FILE__} ruby test-err.rb"
|
7
|
+
puts " #{__FILE__} ruby test-putr.rb"
|
8
|
+
exit -1
|
9
|
+
end
|
10
|
+
|
11
|
+
out = ''
|
12
|
+
captured = ''
|
13
|
+
begin
|
14
|
+
sh ARGV.join(' '), true, captured do |char|
|
15
|
+
putc char
|
16
|
+
end
|
17
|
+
puts esc_green "OK"
|
18
|
+
puts "captured output (captured):"
|
19
|
+
puts captured
|
20
|
+
puts
|
21
|
+
rescue ShellExecutionError => e
|
22
|
+
puts esc_red "ERROR: #{e}, status:#{e.status}, output:"
|
23
|
+
puts e.output
|
24
|
+
puts
|
25
|
+
end
|
data/lib/cli_tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Kukushkin
|
@@ -52,6 +52,15 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
54
|
- cli_tools.gemspec
|
55
|
+
- examples/ex-ansi.rb
|
56
|
+
- examples/ex-block.rb
|
57
|
+
- examples/ex-err.rb
|
58
|
+
- examples/ex-kb-getkey.rb
|
59
|
+
- examples/ex-ok.rb
|
60
|
+
- examples/ex-putr.rb
|
61
|
+
- examples/ex-puts-vs-putr.rb
|
62
|
+
- examples/ex-raise.rb
|
63
|
+
- examples/ex-sh.rb
|
55
64
|
- lib/cli_tools.rb
|
56
65
|
- lib/cli_tools/console.rb
|
57
66
|
- lib/cli_tools/include.rb
|