lucie-cmd 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bcbc57fe509cfa7ca24494812a5af89113184f3
4
- data.tar.gz: e2dc4c4c25c467287773478a09414d105b881a77
3
+ metadata.gz: d5d8773ea556b86dec92d17eac1fa1cc5aa3e06b
4
+ data.tar.gz: a803646cf421dc375bf02d75f83eb380fd5e0353
5
5
  SHA512:
6
- metadata.gz: 0ff3b5da9dce13233b9f803bd20fc1b2a2ee230d78b4077b0c1edee29afb399a28e15395cf20eb48ff735545861ba9e6748a921a716ecf87c39ae00297c27660
7
- data.tar.gz: 7ab81b5d27644870d8a6deadc80a36b5e0042c30734e50de89caa3286a5fd6cd6262e1fa92d309c63e47b6cd89969ed091d6851f69454fb77cc1f63a50a00ec3
6
+ metadata.gz: 2dc123d998ee7961f9b1563d3eac2ebfe982a6c140e4bf2088ea8cbb5e2a10c099c82d006d52c34d7b1334ae222a9d81c51ebe78e50ddea24029adc69e950914
7
+ data.tar.gz: e45baf99b2e45c1509842571bd8401feea221d79015095e621e8d8805e56c948803880d4153b56c41e1d3a64a290a10689d4a0a104663d89031d8634fce033da
@@ -24,15 +24,36 @@ module Lucie
24
24
  @commands_helper.status
25
25
  end
26
26
 
27
- def on(opts = [])
27
+ def set(opts = [])
28
28
  @commands_helper ||= CommandsHelper.new
29
- @commands_helper.on(Array(opts))
29
+ @commands_helper.set(Array(opts))
30
+ end
31
+
32
+ def unset(opts = [])
33
+ @commands_helper ||= CommandsHelper.new
34
+ @commands_helper.unset(Array(opts))
35
+ end
36
+
37
+ def red(text)
38
+ puts colorize(text, 31)
39
+ end
40
+
41
+ def green(text)
42
+ puts colorize(text, 32)
43
+ end
44
+
45
+ def yellow(text)
46
+ puts colorize(text, 33)
47
+ end
48
+
49
+ def colorize(text, color_code)
50
+ "\e[#{color_code}m#{text}\e[0m"
30
51
  end
31
52
 
32
53
  private
33
54
 
34
55
  class CommandsHelper
35
- attr_accessor :pwd
56
+ attr_reader :pwd
36
57
 
37
58
  def initialize
38
59
  @stderr = $stderr
@@ -52,7 +73,7 @@ module Lucie
52
73
  @output = ""
53
74
  if !stdout.eof()
54
75
  new_content = stdout.read
55
- if @opts.include? :live_input
76
+ if @opts.include? :live_output
56
77
  print new_content
57
78
  end
58
79
  @output << new_content
@@ -72,9 +93,13 @@ module Lucie
72
93
  @pwd = File.expand_path(val, @pwd)
73
94
  end
74
95
 
75
- def on(opts = [])
96
+ def set(opts = [])
76
97
  @opts = @opts | opts
77
98
  end
99
+
100
+ def unset(opts = [])
101
+ opts.each { |opt| @opts.delete(opt) }
102
+ end
78
103
  end
79
104
  end
80
105
  end
data/lucie-cmd.gemspec CHANGED
@@ -1,5 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
- version = File.read(File.expand_path('../../version', __FILE__)).strip
2
+ require File.expand_path("../../lucie-lib/lib/lucie/version", __FILE__)
3
+ version = Lucie::VERSION
3
4
  lib = File.expand_path('../lib', __FILE__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
 
@@ -55,19 +55,50 @@ class ShTest < MiniTest::Spec
55
55
  end
56
56
 
57
57
  it "should be able to put the output realtime" do
58
- on :live_input
59
- out, err = capture_io do
58
+ set :live_output
59
+ out, _ = capture_io do
60
60
  sh "echo test"
61
61
  end
62
62
  assert_equal "test\n", out
63
63
  end
64
64
 
65
65
  it "should be able to show the command" do
66
- on :show_command
67
- out, err = capture_io do
66
+ set :show_command
67
+ out, _ = capture_io do
68
68
  sh "echo test"
69
69
  end
70
70
  assert_equal "$ echo test\n", out
71
71
  end
72
72
 
73
+ it "should have an unset to turn off realtime output" do
74
+ set :live_output
75
+ unset :live_output
76
+ out, _ = capture_io do
77
+ sh "echo test"
78
+ end
79
+ assert_equal "", out
80
+ end
81
+
82
+ it "should be able to use green color for output" do
83
+ out, _ = capture_io do
84
+ green "Hello world"
85
+ end
86
+ assert_equal "\e[32mHello world\e[0m\n", out
87
+ end
88
+
89
+ it "should be able to use red color for output" do
90
+ out, _ = capture_io do
91
+ red "Hello world"
92
+ end
93
+ assert_equal "\e[31mHello world\e[0m\n", out
94
+ end
95
+
96
+ it "should be able to use yellow color for output" do
97
+ out, _ = capture_io do
98
+ yellow "Hello world"
99
+ end
100
+ assert_equal "\e[33mHello world\e[0m\n", out
101
+ end
102
+
103
+
73
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucie-cmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nucc