playwright-cli 0.1.15 → 0.1.16

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: b91812a60a063511be0abece0c33ffe5bdf9d5a710298773cfafd136ad85c035
4
- data.tar.gz: 93b6ba02d18968e70e481b6a47e1258ad0da71da2f90fe3db433fa9588de9d13
3
+ metadata.gz: 368e6d76fcbddcc447c51c1aa01f2b026db700402fcc1bfa548a18968e1ffa35
4
+ data.tar.gz: 49222ff68b9e74a729f4e2992407b2c9eba996345b1e9649a064c4d456985c39
5
5
  SHA512:
6
- metadata.gz: e4d1da5ba351dc60e7d7b5969c77b3b5deaadf88e9fe132aab53e8dea08f048d976393f35ee4bb03ece138c36cc6228201204a3a3aa7f7e5f995fcd3d996ee34
7
- data.tar.gz: 635dcdca8ad6dbcd9c9c0df00e49bd93cd0841032deb3133f51de373c3fc0bcefedd3dbbab7f2371d3c5c8f31d63a7007a89fd5abd13763546d95fa559a37d64
6
+ metadata.gz: dbb18e3e1632c70d251650d6c5c0c7f159b457948537824fef5af96908b0f64ab77056c361fb54408c81e98203db5bdda9aaa4c850b519b06849019d50b5e5cf
7
+ data.tar.gz: 4dfaa28467dfdd1f5e0a82ec6494c899e79ae22a50d58f33dcbb0e803aa67a1e1ff36694189c3e70ba3736295866f45abc3704372c15d0f2adc4abccaa25138e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- playwright-cli (0.1.14)
4
+ playwright-cli (0.1.16)
5
5
  colorize (~> 0.1)
6
6
  git (~> 1.3)
7
7
  hanami-cli (~> 0.1)
data/README.md CHANGED
@@ -5,11 +5,30 @@ Ruby command line applications. It's first goal is to provide a solid generator
5
5
  for building command line apps in Ruby. It's built on top of [Hanami::CLI](https://github.com/hanami/cli),
6
6
  so all of their documentation applies here as well.
7
7
 
8
+ ## Table of Contents
9
+
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [Check The Version](#check-the-version)
13
+ - [Create An App](#create-an-app)
14
+ - [Helpers](#helpers)
15
+ - [Display](#display)
16
+ - [Ask](#ask)
17
+ - [OS](#os)
18
+ - [Arguments & Options](#arguments--options)
19
+ - [Validations](#validations)
20
+ - [Edit An App](#edit-an-app)
21
+ - [List Apps](#list-apps)
22
+ - [Delete An App](#delete-an-app)
23
+ - [Contributing](#contributing)
24
+ - [License](#license)
25
+
8
26
  ## Installation
9
27
 
10
28
  Install this gem with:
11
-
29
+ ```shell
12
30
  $ gem install playwright-cli
31
+ ```
13
32
 
14
33
  ## Usage
15
34
 
@@ -17,7 +36,7 @@ Install this gem with:
17
36
 
18
37
  To check the version:
19
38
  ```shell
20
- $ playwright -v #=> 0.1.14
39
+ $ playwright -v #=> 0.1.16
21
40
  ```
22
41
 
23
42
  ### Create An App
@@ -32,46 +51,46 @@ you should replace. The `#call` method is what is ultimately run.
32
51
  It will look something like this:
33
52
 
34
53
  ```ruby
35
- #!/usr/bin/env ruby
54
+ #!/usr/bin/env ruby
36
55
 
37
- require 'bundler/inline'
38
- gemfile do
39
- source 'https://rubygems.org'
40
- gem 'playwright-cli', require: 'playwright/cli'
41
- end
56
+ require 'bundler/inline'
57
+ gemfile do
58
+ source 'https://rubygems.org'
59
+ gem 'playwright-cli', require: 'playwright/cli'
60
+ end
42
61
 
43
- module MyScript
44
- module CLI
45
- module Commands
46
- extend Playwright::CLI::Registry
62
+ module MyScript
63
+ module CLI
64
+ module Commands
65
+ extend Playwright::CLI::Registry
47
66
 
48
- class Root < Playwright::CLI::Command
49
- desc "Says a greeting to the name given. This is an example."
67
+ class Root < Playwright::CLI::Command
68
+ desc "Says a greeting to the name given. This is an example."
50
69
 
51
- argument :name, required: true, desc: 'Whom shall I greet?'
70
+ argument :name, required: true, desc: 'Whom shall I greet?'
52
71
 
53
- example [
54
- "\"Johnny Boy\" #=> Why, hello Johnny Boy!"
55
- ]
72
+ example [
73
+ "\"Johnny Boy\" #=> Why, hello Johnny Boy!"
74
+ ]
56
75
 
57
- def call(name:, **)
58
- puts "Why, hello #{name}!"
59
- end
76
+ def call(name:, **)
77
+ display.print "Why, hello #{name}!"
78
+ end
60
79
 
61
- end
80
+ end
62
81
 
63
- register_root Root
82
+ register_root Root
64
83
 
84
+ end
65
85
  end
66
86
  end
67
- end
68
87
 
69
- Playwright::CLI.new(MyScript::CLI::Commands).call
88
+ Playwright::CLI.new(MyScript::CLI::Commands).call
70
89
 
71
90
  ```
72
91
 
73
92
  ```shell
74
- $ my-script tom #=> Why, hello tom!
93
+ $ my-script tom #=> Why, hello tom!
75
94
  ```
76
95
  Most of this code is simply wrapping [Hanami::CLI](https://github.com/hanami/cli), so their documentation
77
96
  will be the best source of information for you in handling arguments and options.
@@ -87,49 +106,49 @@ as in the example below.
87
106
  Hanami::CLI is built for more intricate command line apps, so playwright allows
88
107
  you to generate that as well.
89
108
  ```shell
90
- $ playwright g my-script --type=expanded
109
+ $ playwright g my-script --type=expanded
91
110
  ```
92
111
  This will give you a mostly similar main class:
93
112
 
94
113
  ```ruby
95
- #!/usr/bin/env ruby
114
+ #!/usr/bin/env ruby
115
+
116
+ require 'bundler/inline'
117
+ gemfile do
118
+ source 'https://rubygems.org'
119
+ gem 'playwright-cli', require: 'playwright/cli'
120
+ end
96
121
 
97
- require 'bundler/inline'
98
- gemfile do
99
- source 'https://rubygems.org'
100
- gem 'playwright-cli', require: 'playwright/cli'
101
- end
122
+ require_relative 'lib/version'
102
123
 
103
- require_relative 'lib/version'
124
+ module MyScript
125
+ module CLI
126
+ module Commands
127
+ extend Playwright::CLI::Registry
104
128
 
105
- module MyScript
106
- module CLI
107
- module Commands
108
- extend Playwright::CLI::Registry
129
+ class Greet < Playwright::CLI::Command
130
+ desc "Says a greeting to the name given. This is an example."
109
131
 
110
- class Greet < Playwright::CLI::Command
111
- desc "Says a greeting to the name given. This is an example."
132
+ argument :name, required: true, desc: 'Whom shall I greet?'
112
133
 
113
- argument :name, required: true, desc: 'Whom shall I greet?'
134
+ example [
135
+ "\"Johnny Boy\" #=> Why, hello Johnny Boy!"
136
+ ]
114
137
 
115
- example [
116
- "\"Johnny Boy\" #=> Why, hello Johnny Boy!"
117
- ]
138
+ def call(name:, **)
139
+ display.print "Why, hello #{name}!"
140
+ end
118
141
 
119
- def call(name:, **)
120
- puts "Why, hello #{name}!"
121
142
  end
122
143
 
123
- end
124
-
125
- register 'greet', Greet
126
- register 'version', Version, aliases: ['v', '-v', '--version']
144
+ register 'greet', Greet
145
+ register 'version', Version, aliases: ['v', '-v', '--version']
127
146
 
147
+ end
128
148
  end
129
149
  end
130
- end
131
150
 
132
- Playwright::CLI.new(MyScript::CLI::Commands).call
151
+ Playwright::CLI.new(MyScript::CLI::Commands).call
133
152
  ```
134
153
  It will also give you a new file structure with an example (version) command:
135
154
  ```
@@ -146,36 +165,36 @@ with aliases.
146
165
 
147
166
  Version class simply looks like this:
148
167
  ```ruby
149
- module MyScript
150
- module CLI
168
+ module MyScript
169
+ module CLI
170
+
171
+ VERSION = "0.0.1"
151
172
 
152
- VERSION = "0.0.1"
173
+ module Commands
174
+ extend Playwright::CLI::Registry
153
175
 
154
- module Commands
155
- extend Playwright::CLI::Registry
176
+ class Version < Playwright::CLI::Command
177
+ desc "Responds with the version number."
156
178
 
157
- class Version < Playwright::CLI::Command
158
- desc "Responds with the version number."
179
+ example ["#=> #{VERSION}"]
159
180
 
160
- example ["#=> #{VERSION}"]
181
+ def call(**)
182
+ display.print VERSION
183
+ end
161
184
 
162
- def call(**)
163
- puts VERSION
164
185
  end
165
186
 
166
187
  end
167
-
168
188
  end
169
189
  end
170
- end
171
190
  ```
172
191
 
173
192
  This is useful for command line apps that will have multiple functions. This
174
193
  example would let you do:
175
194
 
176
195
  ```shell
177
- $ my-script greet tom #=> Why, hello tom!
178
- $ my-script version #=> 0.0.1
196
+ $ my-script greet tom #=> Why, hello tom!
197
+ $ my-script version #=> 0.0.1
179
198
  ```
180
199
 
181
200
  ### Helpers
@@ -195,11 +214,11 @@ A good example would be if you ask a user, "File already exists? Overwrite it?
195
214
  [yn]" and they choose 'n'
196
215
 
197
216
  ```ruby
198
- class Greet < Playwright::CLI::Command
199
- def call(**)
200
- display.print "Hello!", color: :blue
217
+ class Greet < Playwright::CLI::Command
218
+ def call(**)
219
+ display.print "Hello!", color: :blue
220
+ end
201
221
  end
202
- end
203
222
  ```
204
223
 
205
224
  #### Ask
@@ -209,11 +228,11 @@ The Ask helper has 3 actions, `question`, `boolean_question`, and
209
228
  and `url_question` validate the response. `question` does not.
210
229
 
211
230
  ```ruby
212
- class Greet < Playwright::CLI::Command
213
- def call(**)
214
- ask.boolean_question "What's your name?" #=> "What's your name? [yn]"
231
+ class Greet < Playwright::CLI::Command
232
+ def call(**)
233
+ ask.boolean_question "What's your name?" #=> "What's your name? [yn]"
234
+ end
215
235
  end
216
- end
217
236
  ```
218
237
 
219
238
  #### OS
@@ -222,12 +241,25 @@ The OS helper has 2 actions, `open_url` and `open_editor`. `open_url` takes a
222
241
  url and an optional name. `open_editor` takes a path and an optional name.
223
242
 
224
243
  ```ruby
225
- class Greet < Playwright::CLI::Command
226
- def call(**)
227
- os.open_url url: 'http://google.com', name: 'google'
228
- os.open_editor path: Dir.pwd, name: 'working directory'
244
+ class Greet < Playwright::CLI::Command
245
+ def call(**)
246
+ os.open_url url: 'http://google.com', name: 'google'
247
+ os.open_editor path: Dir.pwd, name: 'working directory'
248
+ end
229
249
  end
230
- end
250
+ ```
251
+
252
+
253
+ ### Arguments & Options
254
+
255
+ #### Validations
256
+
257
+ You can add validations to your arguments and options by passing a proc or an
258
+ array of procs to your argument or option declaration. The script will throw an
259
+ error if the proc evaluates to false
260
+
261
+ ```
262
+ argument :url, validations: Proc.new { |url| URL_REGEX =~ url }
231
263
  ```
232
264
 
233
265
  ### Edit An App
@@ -238,7 +270,7 @@ editor to use when opening one of your playwright scripts.
238
270
  Use:
239
271
 
240
272
  ```shell
241
- $ echo $EDITOR
273
+ $ echo $EDITOR
242
274
  ```
243
275
 
244
276
  To see what playwright will default to. You can update this in your ~/.bashrc
@@ -249,7 +281,7 @@ In the future, I plan on allowing that to be a config you can set
249
281
  To edit an app:
250
282
 
251
283
  ```shell
252
- $ playwright edit my-script
284
+ $ playwright edit my-script
253
285
  ```
254
286
 
255
287
  `e` can be used instead of `edit`.
@@ -259,7 +291,7 @@ $ playwright edit my-script
259
291
  To see all Playwright apps, use:
260
292
 
261
293
  ```shell
262
- $ playwright list
294
+ $ playwright list
263
295
  ```
264
296
 
265
297
  `l`, `-l`, `--list` can be used instead of `list`.
@@ -269,7 +301,7 @@ $ playwright list
269
301
  Deleting a playwright app is simply:
270
302
 
271
303
  ```shell
272
- $ playwright destroy my-script
304
+ $ playwright destroy my-script
273
305
  ```
274
306
 
275
307
  `delete` or `d` can be used instead of `destroy`
@@ -0,0 +1,11 @@
1
+ module Hanami
2
+ class CLI
3
+ class Option
4
+
5
+ def validations
6
+ options[:validations] || []
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,42 @@
1
+ module Hanami
2
+ class CLI
3
+ module Parser
4
+
5
+ # Copied and adjusted from hanami/cli codebase to handle validations
6
+ def self.call(command, arguments, names)
7
+
8
+ command.arguments.map.with_index do |arg, idx|
9
+ arg_value = arguments[idx]
10
+ unless [*arg.validations].all? { |validation| validation.call(arg_value) }
11
+ return Result.failure "Error: Invalid argument provided: #{arg_value}" if arg_value
12
+ end
13
+ end
14
+
15
+ parsed_options = {}
16
+
17
+ OptionParser.new do |opts|
18
+ command.options.each do |option|
19
+ opts.on(*option.parser_options) do |value|
20
+ # This conditional enforces validations
21
+ if option.validations.all? { |validation| validation.call(value) }
22
+ parsed_options[option.name.to_sym] = value
23
+ else
24
+ return Result.failure "Error: Invalid option provided: #{option.name}"
25
+ end
26
+ end
27
+ end
28
+
29
+ opts.on_tail("-h", "--help") do
30
+ return Result.help
31
+ end
32
+ end.parse!(arguments)
33
+
34
+ parsed_options = command.default_params.merge(parsed_options)
35
+ parse_required_params(command, arguments, names, parsed_options)
36
+ rescue ::OptionParser::ParseError
37
+ return Result.failure
38
+ end
39
+
40
+ end
41
+ end
42
+ end
data/lib/ext/hanami.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative 'hanami/option'
2
+ require_relative 'hanami/parser'
@@ -2,6 +2,6 @@ require 'hanami/cli'
2
2
 
3
3
  module Playwright
4
4
  class CLI < Hanami::CLI
5
- VERSION = "0.1.15"
5
+ VERSION = "0.1.16"
6
6
  end
7
7
  end
@@ -8,6 +8,8 @@ require 'os'
8
8
  require 'uri'
9
9
  require 'pathname'
10
10
 
11
+ require_relative '../ext/hanami.rb'
12
+
11
13
  module Playwright
12
14
  class CLI < Hanami::CLI
13
15
  ROOT_PATH = Pathname.new(File.expand_path('../..', File.dirname(__FILE__)))
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.15
4
+ version: 0.1.16
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-04-03 00:00:00.000000000 Z
11
+ date: 2018-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -173,6 +173,9 @@ files:
173
173
  - lib/assets/templates/script_readme_template.erb
174
174
  - lib/assets/templates/simple_script_template.erb
175
175
  - lib/assets/templates/version_subcommand_template.erb
176
+ - lib/ext/hanami.rb
177
+ - lib/ext/hanami/option.rb
178
+ - lib/ext/hanami/parser.rb
176
179
  - lib/playwright/cli.rb
177
180
  - lib/playwright/cli/command.rb
178
181
  - lib/playwright/cli/commands.rb