playwright-cli 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +177 -14
- data/lib/playwright/cli/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77a1822555e09c749d2408b29496ca5840553bd45decf3c1f24ee8f87448e8e0
|
4
|
+
data.tar.gz: a97277bfb37d67ad68099f362db4c3fd2c5a8243da676b727723f7b703cda2fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fc6645dc4cbd4305c35caea58c1c50ca7335f875eb2d7c490428bb6314e03d93b0f3437ed1f4ca0007f2c2affaa3bd741df3d6d39c73db3e042b19862128ca4
|
7
|
+
data.tar.gz: 66ca9d2e2ef45e96e449b0bf41593ecf483b1bbf45084b2ab5a71508df5526d5a3936be6731080a3b212474ae1bf8f9017a8ec441017cb85f48cbc5dfb973cd9
|
data/README.md
CHANGED
@@ -1,34 +1,197 @@
|
|
1
1
|
# Playwright::CLI
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Playwright::CLI is a tool for quickly building (and hopefully soon sharing)
|
4
|
+
Ruby command line applications. It's first goal is to provide a solid generator
|
5
|
+
for building command line apps in Ruby. It's built on top of [Hanami::CLI](https://github.com/hanami/cli),
|
6
|
+
so all of their documentation applies here as well.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
9
|
-
|
10
|
+
Install this gem with:
|
11
|
+
|
12
|
+
$ gem install playwright-cli
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
### Check The Version
|
17
|
+
|
18
|
+
To check the version:
|
19
|
+
```shell
|
20
|
+
$ playwright -v #=> 0.1.4
|
21
|
+
```
|
22
|
+
|
23
|
+
### Create An App
|
24
|
+
|
25
|
+
To create a simple command line app:
|
26
|
+
|
27
|
+
$ playwright generate my-script
|
28
|
+
|
29
|
+
(aliases for `generate` include `g`, `new`)
|
30
|
+
This will give you some boilerplate for your script and an example command that
|
31
|
+
you should replace. It will look something like this:
|
10
32
|
|
11
33
|
```ruby
|
12
|
-
|
34
|
+
#!/usr/bin/env ruby
|
35
|
+
|
36
|
+
require 'playwright/cli'
|
37
|
+
|
38
|
+
module MyScript
|
39
|
+
module CLI
|
40
|
+
module Commands
|
41
|
+
extend Playwright::CLI::Registry
|
42
|
+
|
43
|
+
class Root < Playwright::CLI::Command
|
44
|
+
desc "Says a greeting to the name given. This is an example."
|
45
|
+
|
46
|
+
argument :name, required: true, desc: 'Whom shall I greet?'
|
47
|
+
|
48
|
+
example [
|
49
|
+
"\"Johnny Boy\" #=> Why, hello Johnny Boy!"
|
50
|
+
]
|
51
|
+
|
52
|
+
def call(name:, **)
|
53
|
+
puts "Why, hello #{name}!"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
register_root Root
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Playwright::CLI.new(MyScript::CLI::Commands).call
|
65
|
+
|
66
|
+
```
|
67
|
+
|
68
|
+
Most of this code is simply wrapping [Hanami::CLI](https://github.com/hanami/cli), so their documentation
|
69
|
+
will be the best source of information for you in handling arguments and options.
|
70
|
+
|
71
|
+
So far, only `#register_root` here is a playwright feature. It allows you to
|
72
|
+
overwrite the root command. In this case that means:
|
73
|
+
```shell
|
74
|
+
$ my-script tom #=> Why, hello tom!
|
75
|
+
```
|
76
|
+
|
77
|
+
Hanami::CLI is built for more intricate command line apps, so playwright allows
|
78
|
+
you to generate that as well.
|
79
|
+
```shell
|
80
|
+
$ playwright g my-script --type=expanded
|
13
81
|
```
|
82
|
+
This will give you a mostly similar main class:
|
14
83
|
|
15
|
-
|
84
|
+
```ruby
|
85
|
+
#!/usr/bin/env ruby
|
16
86
|
|
17
|
-
|
87
|
+
require 'playwright/cli'
|
88
|
+
require_relative 'lib/version'
|
18
89
|
|
19
|
-
|
90
|
+
module MyScript
|
91
|
+
module CLI
|
92
|
+
module Commands
|
93
|
+
extend Playwright::CLI::Registry
|
20
94
|
|
21
|
-
|
95
|
+
class Greet < Playwright::CLI::Command
|
96
|
+
desc "Says a greeting to the name given. This is an example."
|
22
97
|
|
23
|
-
|
98
|
+
argument :name, required: true, desc: 'Whom shall I greet?'
|
99
|
+
|
100
|
+
example [
|
101
|
+
"\"Johnny Boy\" #=> Why, hello Johnny Boy!"
|
102
|
+
]
|
24
103
|
|
25
|
-
|
104
|
+
def call(name:, **)
|
105
|
+
puts "Why, hello #{name}!"
|
106
|
+
end
|
26
107
|
|
27
|
-
|
108
|
+
end
|
28
109
|
|
29
|
-
|
110
|
+
register 'greet', Greet
|
111
|
+
register 'version', Version, aliases: ['v', '-v', '--version']
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
Playwright::CLI.new(MyScript::CLI::Commands).call
|
118
|
+
```
|
119
|
+
It will also give you a new file structure with an example (version) command:
|
120
|
+
```
|
121
|
+
my-script
|
122
|
+
|- lib/
|
123
|
+
| |- version.rb
|
124
|
+
|- my-script.rb
|
125
|
+
```
|
126
|
+
The main differences are that a new file lib/version is required and registered
|
127
|
+
with aliases.
|
128
|
+
|
129
|
+
Version class simply looks like this:
|
130
|
+
```ruby
|
131
|
+
module MyScript
|
132
|
+
module CLI
|
133
|
+
|
134
|
+
VERSION = "0.0.1"
|
135
|
+
|
136
|
+
module Commands
|
137
|
+
extend Playwright::CLI::Registry
|
138
|
+
|
139
|
+
class Version < Playwright::CLI::Command
|
140
|
+
desc "Responds with the version number."
|
141
|
+
|
142
|
+
example ["#=> #{VERSION}"]
|
143
|
+
|
144
|
+
def call(**)
|
145
|
+
puts VERSION
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
This is useful for command line apps that will have multiple functions. This
|
156
|
+
example would let you do:
|
157
|
+
|
158
|
+
```shell
|
159
|
+
$ my-script greet tom #=> Why, hello tom!
|
160
|
+
$ my-script version #=> 0.0.1
|
161
|
+
```
|
162
|
+
|
163
|
+
|
164
|
+
### Edit An App
|
165
|
+
|
166
|
+
Playwright::CLI uses your `$EDITOR` environment variable when choosing what
|
167
|
+
editor to use when opening one of your playwright scripts.
|
168
|
+
|
169
|
+
Use:
|
170
|
+
|
171
|
+
`$ echo $EDITOR`
|
172
|
+
|
173
|
+
To see what playwright will default to. You can update this in your ~/.bashrc
|
174
|
+
(or ~/.zshrc if you are using zsh).
|
175
|
+
|
176
|
+
In the future, I plan on allowing that to be a config you can set
|
177
|
+
|
178
|
+
To edit an app:
|
179
|
+
|
180
|
+
`$ playwright edit my-script`
|
181
|
+
|
182
|
+
`e` can be used instead of `edit`.
|
183
|
+
|
184
|
+
### Delete An App
|
185
|
+
|
186
|
+
Deleting a playwright app is simply:
|
187
|
+
|
188
|
+
```shell
|
189
|
+
$ playwright destroy my-script
|
190
|
+
```
|
30
191
|
|
31
|
-
|
192
|
+
`delete` or `d` can be used instead of `destroy`
|
193
|
+
This works for both simple and expanded apps. It cannot be used to delete or
|
194
|
+
uninstall existing terminal commands, only playwright commands
|
32
195
|
|
33
196
|
## Contributing
|
34
197
|
|