arli 0.8.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,186 +0,0 @@
1
- require 'colored2'
2
- require 'tty-cursor'
3
-
4
- module Arli
5
- module Output
6
- CHAR_FAILURE = '✖'.red
7
- CHAR_SUCCESS = '✔'.green
8
-
9
- class << self
10
- attr_accessor :enabled, :cursor
11
-
12
- def enable!
13
- self.enabled = true
14
- end
15
-
16
- def enabled?
17
- self.enabled
18
- end
19
-
20
- def disable!
21
- self.enabled = false
22
- end
23
- end
24
-
25
- self.enable!
26
- self.cursor = TTY::Cursor
27
-
28
- def cursor
29
- Arli::Output.cursor
30
- end
31
-
32
- def info(msg, header = nil)
33
- __pf('%-20s', header.blue) if header
34
- __pf((header ? ' : ' : '') + msg + "\n") if msg
35
- end
36
-
37
- def debug(msg)
38
- __pf('%-20s', header.blue) if header
39
- __pf((header ? ' : ' : '') + msg + "\n") if msg
40
- end
41
-
42
- def error(msg, exception = nil)
43
- __pf "#{msg.to_s.red}\n" if msg
44
- __pf "#{exception.inspect.red}\n\n" if exception
45
- end
46
-
47
- def report_exception(e, header = nil)
48
- if header
49
- __pf header.bold.yellow + ': '
50
- else
51
- __pf 'Error: '.bold.red
52
- end
53
- error e.message if (e && e.respond_to?(:message))
54
- if e && Arli.config.trace
55
- __pf "\n"
56
- __pf 'Top 10 stack trace'.bold.yellow + "\n"
57
- __pf e.backtrace.reverse[-10..-1].join("\n").red + "\n"
58
- elsif e
59
- __pf "\nUse -t (--trace) for detailed exception\n" +
60
- "or -D (--debug) to print Arli config\n"
61
- end
62
- end
63
-
64
- def raise_invalid_arli_command!(cmd, e = nil)
65
- raise Arli::Errors::InvalidCommandError.new(cmd)
66
- end
67
-
68
- # Shortcuts disabled in tests
69
- def ___(msg = nil, newline = false)
70
- return unless Arli::Output.enabled?
71
- __pf msg if msg
72
- __pt if newline
73
- end
74
-
75
- def __pt(*args)
76
- puts(*args) if Arli::Output.enabled?
77
- end
78
-
79
- def __p(*args)
80
- print(*args) if Arli::Output.enabled?
81
- end
82
-
83
- def __pf(*args)
84
- printf(*args) if Arli::Output.enabled?
85
- end
86
-
87
-
88
- def print_target_dir(d, verb = 'installed')
89
- print_action_success(d.green, "#{verb} #{d.green} ")
90
- end
91
-
92
- def print_action_starting(action_name)
93
- if verbose?
94
- indent_cursor
95
- ___ "⇨ #{action_name.yellow} ... "
96
- end
97
- if block_given?
98
- yield
99
- ok if verbose?
100
- end
101
- end
102
-
103
- def print_action_success(short, verbose = nil)
104
- if verbose? && !quiet?
105
- indent_cursor
106
- ___ "⇨ #{verbose || short} #{CHAR_SUCCESS}"
107
- elsif !quiet?
108
- ___ "#{short} #{CHAR_SUCCESS} "
109
- end
110
- end
111
-
112
- def print_action_failure(short, verbose = nil)
113
- if verbose? && !quiet?
114
- indent_cursor
115
- ___ "⇨ #{verbose || short} #{CHAR_FAILURE}\n"
116
- elsif !quiet?
117
- ___ "#{short} #{CHAR_FAILURE} "
118
- end
119
- end
120
-
121
- def action_fail(action, exception)
122
- print_action_failure(action.class.action_name,
123
- "#{action.class.action_name} failed with #{exception.message.red}\n" +
124
- "Action Description: #{action.class.description}")
125
- raise(exception)
126
- end
127
-
128
- def action_ok(action)
129
- print_action_success(action.action_name)
130
- end
131
-
132
- def ok
133
- ___ " #{CHAR_SUCCESS} "
134
- end
135
-
136
- def fuck
137
- ___ " #{CHAR_FAILURE} "
138
- end
139
-
140
- def header(command: nil)
141
- out = "\n#{hr}\n"
142
- out << "Arli (#{::Arli::VERSION.yellow})"
143
- out << ", Command: #{command.name.to_s.magenta.bold}" if command
144
- if command && command.params && Arli.config.verbose
145
- out << "\n#{command.params.to_s.blue}\n"
146
- end
147
- out << "\nLibrary Path: #{Arli.default_library_path.green}\n"
148
- out << "#{hr}\n"
149
- info out
150
- end
151
-
152
- def hr
153
- ('-' * (ENV['COLUMNS'] || 80)).red.dark
154
- end
155
-
156
- # Some shortcuts
157
- def verbose?
158
- config.verbose && !quiet?
159
- end
160
-
161
- def quiet?
162
- config.quiet
163
- end
164
-
165
- def overwrite?
166
- config.if_exists.overwrite
167
- end
168
-
169
- def backup?
170
- config.if_exists.backup
171
- end
172
-
173
- def abort?
174
- config.if_exists.abort
175
- end
176
-
177
- def debug?
178
- config.debug
179
- end
180
-
181
- private
182
- def indent_cursor
183
- ___ cursor.column(40)
184
- end
185
- end
186
- end