playwright-cli 0.1.6 → 0.1.8

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
  SHA256:
3
- metadata.gz: 7d15ffbd0519e6d34a44de4d25c24d474ceb484d2197de04daa2844f9569e68e
4
- data.tar.gz: ba61f21062a324708dbdb9608af6fa521e985861ce7c13ee8b50b6ef8e43374f
3
+ metadata.gz: 7d87579b2ff3473151b43b2ba48189ecc51ac5191d0ca04f25854e312304b0ab
4
+ data.tar.gz: e0c6dabc8b3744c2e6e9017f9b16ef07bcea7abf0d630f28cc5d3f928e84c3b6
5
5
  SHA512:
6
- metadata.gz: 809012d19a8010bf1284a2bc27cb2ce52c85289008792b97d4872ef79fceaf1b85e463ab25c33c47bd6af7f171a5c92a237d64ea92d8764f7c9e5c966d706a17
7
- data.tar.gz: fa839b93644993dbf016a0bfde9e1eb4ad74294ccb31aacfac0aa5c0fc18b2a8c0f70f24cb43c94ce358730797e848d7d8fbcc584643b3ce4e58f0addee73493
6
+ metadata.gz: fbc645bc301c06dc95c08799927c5975540b9b972128629ece2f829c523508ebaa0c25b321f38810f5fb8fd3fa9c5317ea795b350d719adeae7acaeaca6dabfc
7
+ data.tar.gz: 7f69dee107031ac44616a9c29fb1d494d082172db9409fcad23ce9a72c2384f23ab38cc9837d2d39e9e4ef6b4a0487aab1364d3e94a1d3e93bfef61e5d4374c5
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
  /plays/
13
13
  .ruby-version
14
14
  .commit-msg
15
+ *.gem
16
+ .trello
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- playwright-cli (0.1.6)
4
+ playwright-cli (0.1.8)
5
5
  colorize (~> 0.1)
6
6
  hanami-cli (~> 0.1)
7
7
 
@@ -20,6 +20,7 @@ GEM
20
20
  transproc (~> 1.0)
21
21
  memfs (1.0.0)
22
22
  method_source (0.9.0)
23
+ os (1.0.0)
23
24
  pry (0.9.12.6)
24
25
  coderay (~> 1.0)
25
26
  method_source (~> 0.8)
@@ -49,6 +50,7 @@ PLATFORMS
49
50
  DEPENDENCIES
50
51
  bundler (~> 1.16)
51
52
  memfs (~> 1.0)
53
+ os (~> 1.0)
52
54
  playwright-cli!
53
55
  pry (~> 0.9.0)
54
56
  pry-nav (~> 0.2.4)
data/README.md CHANGED
@@ -161,6 +161,57 @@ $ my-script greet tom #=> Why, hello tom!
161
161
  $ my-script version #=> 0.0.1
162
162
  ```
163
163
 
164
+ ### Helpers
165
+
166
+ Inside of your command, you have access to a few helper objects to make
167
+ interactions easier. You can see any of your helpers actions by calling the
168
+ `#actions` method on it.
169
+
170
+ #### Display
171
+
172
+ The Display helper has 3 actions, `print`, `error`, and `abort`. Each takes a
173
+ message as the first argument and can optionally take a color. `error` and
174
+ `abort` also exit the program.
175
+
176
+ `abort` should be used over `error` only if the user has triggered the exit.
177
+ A good example would be if you ask a user, "File already exists? Overwrite it?
178
+ [yn]" and they choose 'n'
179
+
180
+ ```ruby
181
+ class Greet < Playwright::CLI::Command
182
+ def call(**)
183
+ display.print "Hello!", color: :blue
184
+ end
185
+ end
186
+ ```
187
+
188
+ #### Ask
189
+
190
+ The Ask helper has 3 actions, `question`, `boolean_question`, and
191
+ `url_question`. Each takes a message as the only argument. `boolean_question`
192
+ and `url_question` validate the response. `question` does not.
193
+
194
+ ```ruby
195
+ class Greet < Playwright::CLI::Command
196
+ def call(**)
197
+ ask.boolean_question "What's your name?" #=> "What's your name? [yn]"
198
+ end
199
+ end
200
+ ```
201
+
202
+ #### OS
203
+
204
+ The OS helper has 2 actions, `open_url` and `open_editor`. `open_url` takes a
205
+ url and an optional name. `open_editor` takes a path and an optional name.
206
+
207
+ ```ruby
208
+ class Greet < Playwright::CLI::Command
209
+ def call(**)
210
+ os.open_url url: 'http://google.com', name: 'google'
211
+ os.open_editor path: Dir.pwd, name: 'working directory'
212
+ end
213
+ end
214
+ ```
164
215
 
165
216
  ### Edit An App
166
217
 
@@ -18,7 +18,7 @@ module <%= klass_name %>
18
18
  ]
19
19
 
20
20
  def call(name:, **)
21
- puts "Why, hello #{name}!"
21
+ display.print "Why, hello #{name}!"
22
22
  end
23
23
 
24
24
  end
@@ -17,7 +17,7 @@ module <%= klass_name %>
17
17
  ]
18
18
 
19
19
  def call(name:, **)
20
- puts "Why, hello #{name}!"
20
+ display.print "Why, hello #{name}!"
21
21
  end
22
22
 
23
23
  end
@@ -12,7 +12,7 @@ module <%= klass_name %>
12
12
  example ["#=> #{VERSION}"]
13
13
 
14
14
  def call(**)
15
- puts VERSION
15
+ display.print VERSION
16
16
  end
17
17
 
18
18
  end
@@ -2,6 +2,9 @@ require 'hanami/cli'
2
2
  require 'colorize'
3
3
  require 'fileutils'
4
4
  require 'erb'
5
+ require 'os'
6
+ require 'uri'
7
+ require 'pathname'
5
8
 
6
9
  # TODO: Remove this
7
10
  require 'pry'
@@ -5,6 +5,7 @@ module Playwright
5
5
  class Command < Hanami::CLI::Command
6
6
  include CLI::Utils::Ask
7
7
  include CLI::Utils::Display
8
+ include CLI::Utils::OS
8
9
  end
9
10
  end
10
11
  end
@@ -1,6 +1,8 @@
1
1
  require 'playwright/cli/utils/ask'
2
2
  require 'playwright/cli/utils/display'
3
3
  require 'playwright/cli/utils/file_manager'
4
+ require 'playwright/cli/utils/os'
5
+ require 'playwright/cli/utils/util'
4
6
 
5
7
  module Playwright
6
8
  class CLI < Hanami::CLI
@@ -1,3 +1,4 @@
1
+ require 'playwright/cli/utils/util'
1
2
  require 'playwright/cli/utils/display'
2
3
 
3
4
  module Playwright
@@ -9,20 +10,33 @@ module Playwright
9
10
  @ask ||= Ask.new
10
11
  end
11
12
 
12
- class Ask
13
+ class Ask < Util
13
14
  include Display
14
15
 
15
- DEFAULT_COLOR = :blue
16
+ DEFAULT_COLOR = :light_blue
16
17
  TRUE_RESPONSE = :y
17
18
  FALSE_RESPONSE = :n
18
19
 
19
- def boolean_question question
20
- display.color_print "#{question} [yn]", color: DEFAULT_COLOR
21
- response = $stdin.gets
20
+ def boolean_question user_question
21
+ response = question "#{user question} [yn]"
22
22
  sanitized_response = response.chomp.strip.downcase.to_sym if response && response.length > 0
23
23
  boolean_response_map[response]
24
24
  end
25
25
 
26
+ def url_question user_question
27
+ response = question user_question
28
+ if response =~ URI::regexp
29
+ response
30
+ else
31
+ display.error "Invalid URL!"
32
+ end
33
+ end
34
+
35
+ def question user_question
36
+ display.print "#{user_question} ", color: DEFAULT_COLOR, method: :print
37
+ $stdin.gets
38
+ end
39
+
26
40
  private
27
41
 
28
42
  def boolean_response_map
@@ -1,3 +1,4 @@
1
+ require 'playwright/cli/utils/util'
1
2
  module Playwright
2
3
  class CLI < Hanami::CLI
3
4
  module Utils
@@ -7,8 +8,8 @@ module Playwright
7
8
  @display ||= Display.new
8
9
  end
9
10
 
10
- class Display
11
-
11
+ class Display < Util
12
+
12
13
  InvalidPrintMethod = Class.new StandardError
13
14
 
14
15
  VALID_PRINT_METHODS = [:p, :puts, :print]
@@ -17,19 +18,19 @@ module Playwright
17
18
  ERROR_COLOR = :red
18
19
 
19
20
  def error msg, msg2 = nil
20
- color_print msg, color: :red
21
- color_print "Action Cancelled.", color: ERROR_COLOR
22
- color_print msg2, color: ERROR_COLOR if msg2
23
- exit
21
+ print msg, color: :red
22
+ print "Action Cancelled.", color: ERROR_COLOR
23
+ print msg2, color: ERROR_COLOR if msg2
24
+ exit 1
24
25
  end
25
26
 
26
27
  def abort msg = nil
27
- color_print msg, color: WARNING_COLOR if msg
28
- color_print "Action Cancelled.", color: WARNING_COLOR
29
- exit
28
+ print msg, color: WARNING_COLOR if msg
29
+ print "Action Cancelled.", color: WARNING_COLOR
30
+ exit 1
30
31
  end
31
32
 
32
- def color_print msg, method: :puts, color: DEFAULT_COLOR
33
+ def print msg, method: :puts, color: DEFAULT_COLOR
33
34
  validate_print_method!(method)
34
35
  msg = msg.send(color) if defined?(Colorize)
35
36
  send(method, msg)
@@ -1,5 +1,6 @@
1
1
  require 'playwright/cli/utils/ask'
2
2
  require 'playwright/cli/utils/display'
3
+ require 'playwright/cli/utils/os'
3
4
  require 'playwright/cli/configuration'
4
5
  require 'playwright/cli/template'
5
6
 
@@ -40,12 +41,7 @@ module Playwright
40
41
 
41
42
  def open_editor script_name: nil
42
43
  @script_name ||= script_name
43
- %x[$EDITOR #{root_dir}]
44
- if $?.success?
45
- display.color_print "Opening `#{@script_name}` in your editor..."
46
- else
47
- display.error "Could not open Editor!"
48
- end
44
+ os.open_editor name: @script_name, path: root_dir
49
45
  end
50
46
 
51
47
  def script_name_rb
@@ -140,9 +136,9 @@ module Playwright
140
136
  validate_before_create_script_files!
141
137
  self.class.create_file_structure
142
138
  FileUtils.mkdir_p root_dir
143
- display.color_print "New Directory Created: #{root_dir}"
139
+ display.print "New Directory Created: #{root_dir}"
144
140
  FileUtils.touch executable_file
145
- display.color_print "New File Created: #{executable_file}"
141
+ display.print "New File Created: #{executable_file}"
146
142
  create_expanded_files if type == :expanded
147
143
  end
148
144
 
@@ -153,7 +149,7 @@ module Playwright
153
149
 
154
150
  def set_permissions
155
151
  FileUtils.chmod "u+x", executable_file
156
- display.color_print "Executable Permissions Set: #{executable_file}"
152
+ display.print "Executable Permissions Set: #{executable_file}"
157
153
  end
158
154
 
159
155
  def write_template
@@ -171,7 +167,7 @@ module Playwright
171
167
 
172
168
  def create_symlink
173
169
  FileUtils.symlink(executable_file, symlink_file)
174
- display.color_print "New Symlink Created: #{symlink_file} from #{executable_file}"
170
+ display.print "New Symlink Created: #{symlink_file} from #{executable_file}"
175
171
  end
176
172
 
177
173
  def validate_before_create_script_files!
@@ -194,7 +190,7 @@ module Playwright
194
190
  validate_before_delete_script_files!
195
191
  FileUtils.rm_rf root_dir
196
192
  FileUtils.rm symlink_file
197
- display.color_print "Playwright script '#{script_name}' destroyed!"
193
+ display.print "Playwright script '#{script_name}' destroyed!"
198
194
  end
199
195
 
200
196
  def validate_before_delete_script_files!
@@ -0,0 +1,36 @@
1
+ require 'playwright/cli/utils/util'
2
+ require 'playwright/cli/utils/display'
3
+
4
+ module Playwright
5
+ class CLI < Hanami::CLI
6
+ module Utils
7
+ module OS
8
+
9
+ def os
10
+ @os ||= OS.new
11
+ end
12
+
13
+ class OS < Util
14
+ include Display
15
+
16
+ def open_url url:, name: URI(url).host
17
+ if %x[ #{::OS.open_file_command} #{url} ]
18
+ display.print "Opening #{name} in your default browser..."
19
+ else
20
+ display.error "Failed to open your browser!"
21
+ end
22
+ end
23
+
24
+ def open_editor path:, name: Pathname.new(path).base
25
+ if %x[ $EDITOR #{path} ]
26
+ display.print "Opening #{name} in your default editor..."
27
+ else
28
+ display.error "Failed to open your editor!"
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ module Playwright
2
+ class CLI < Hanami::CLI
3
+ module Utils
4
+ class Util
5
+
6
+ def actions
7
+ self.class.public_instance_methods - Object.public_instance_methods
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Playwright
2
2
  class CLI < Hanami::CLI
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.8"
4
4
  end
5
5
  end
@@ -36,7 +36,8 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "rspec", "~> 3.0"
37
37
  spec.add_development_dependency "pry", "~> 0.9.0"
38
38
  spec.add_development_dependency "pry-nav", "~> 0.2.4"
39
- spec.add_development_dependency "memfs", "~> 1.0"
39
+ spec.add_development_dependency "memfs", "~> 1.0"
40
+ spec.add_development_dependency "os", "~> 1.0"
40
41
 
41
42
  spec.add_runtime_dependency "hanami-cli", "~>0.1"
42
43
  spec.add_runtime_dependency "colorize", "~>0.1"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playwright-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Gregory
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-29 00:00:00.000000000 Z
11
+ date: 2018-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: os
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: hanami-cli
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -161,6 +175,8 @@ files:
161
175
  - lib/playwright/cli/utils/ask.rb
162
176
  - lib/playwright/cli/utils/display.rb
163
177
  - lib/playwright/cli/utils/file_manager.rb
178
+ - lib/playwright/cli/utils/os.rb
179
+ - lib/playwright/cli/utils/util.rb
164
180
  - lib/playwright/cli/version.rb
165
181
  - playwright-cli.gemspec
166
182
  homepage: https://github.com/mgreg90/playwright-cli