dorian 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ci.yml +38 -0
- data/.gitignore +30 -0
- data/.node-version +1 -0
- data/.prettierignore +2 -0
- data/.rubocop.yml +129 -0
- data/.ruby-version +1 -0
- data/.tool-versions +3 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +186 -0
- data/LICENSE +19 -0
- data/README.md +24 -0
- data/VERSION +1 -1
- data/bin/bundle +123 -0
- data/bin/bundle-audit +31 -0
- data/bin/bundler-audit +31 -0
- data/bin/rspec +31 -0
- data/bin/rubocop +31 -0
- data/dorian.gemspec +35 -0
- data/lib/dorian/bin.rb +739 -81
- data/package-lock.json +39 -0
- data/package.json +11 -0
- data/samples/books.json +33 -0
- data/samples/books.jsonl +3 -0
- data/samples/config.yml +27 -0
- data/samples/config_2.yml +22 -0
- data/samples/maths.js +1 -0
- data/samples/numbers.raw +10 -0
- data/samples/people.csv +6 -0
- data/samples/people.yml +28 -0
- data/samples/query.sql +7 -0
- data/samples/user.json +31 -0
- data/spec/dorian_spec.rb +276 -0
- data/spec/spec_helper.rb +3 -0
- data/vendor/groovy-beautify/LICENSE.MD +21 -0
- data/vendor/groovy-beautify/README.md +65 -0
- data/vendor/groovy-beautify/dist/__tests__/index.test.d.ts +1 -0
- data/vendor/groovy-beautify/dist/cjs/index.js +573 -0
- data/vendor/groovy-beautify/dist/cjs/package.json +3 -0
- data/vendor/groovy-beautify/dist/es/index.js +682 -0
- data/vendor/groovy-beautify/dist/es/package.json +3 -0
- data/vendor/groovy-beautify/dist/formatter/FormatRule.d.ts +14 -0
- data/vendor/groovy-beautify/dist/formatter/Formatter.d.ts +11 -0
- data/vendor/groovy-beautify/dist/formatter/GroovyFormatRules.d.ts +3 -0
- data/vendor/groovy-beautify/dist/formatter/__tests__/formatter.test.d.ts +1 -0
- data/vendor/groovy-beautify/dist/index.d.ts +5 -0
- data/vendor/groovy-beautify/dist/parser/GroovyParseRules.d.ts +3 -0
- data/vendor/groovy-beautify/dist/parser/ParseRule.d.ts +23 -0
- data/vendor/groovy-beautify/dist/parser/Parser.d.ts +29 -0
- data/vendor/groovy-beautify/dist/parser/__tests__/parser.test.d.ts +1 -0
- data/vendor/groovy-beautify/dist/parser/types.d.ts +6 -0
- data/vendor/groovy-beautify/dist/utils/text.d.ts +4 -0
- data/vendor/groovy-beautify/package.json +55 -0
- data/vendor/prettier/LICENSE +4379 -0
- data/vendor/prettier/README.md +109 -0
- data/vendor/prettier/bin/prettier.cjs +71 -0
- data/vendor/prettier/doc.d.ts +243 -0
- data/vendor/prettier/doc.js +1545 -0
- data/vendor/prettier/doc.mjs +1503 -0
- data/vendor/prettier/index.cjs +825 -0
- data/vendor/prettier/index.d.ts +941 -0
- data/vendor/prettier/index.mjs +25899 -0
- data/vendor/prettier/internal/cli.mjs +4366 -0
- data/vendor/prettier/package.json +198 -0
- data/vendor/prettier/plugins/acorn.d.ts +6 -0
- data/vendor/prettier/plugins/acorn.js +6618 -0
- data/vendor/prettier/plugins/acorn.mjs +6456 -0
- data/vendor/prettier/plugins/angular.d.ts +8 -0
- data/vendor/prettier/plugins/angular.js +2435 -0
- data/vendor/prettier/plugins/angular.mjs +2375 -0
- data/vendor/prettier/plugins/babel.d.ts +18 -0
- data/vendor/prettier/plugins/babel.js +14271 -0
- data/vendor/prettier/plugins/babel.mjs +13986 -0
- data/vendor/prettier/plugins/estree.d.ts +1 -0
- data/vendor/prettier/plugins/estree.js +9487 -0
- data/vendor/prettier/plugins/estree.mjs +9279 -0
- data/vendor/prettier/plugins/flow.d.ts +5 -0
- data/vendor/prettier/plugins/flow.js +51477 -0
- data/vendor/prettier/plugins/flow.mjs +51219 -0
- data/vendor/prettier/plugins/glimmer.d.ts +5 -0
- data/vendor/prettier/plugins/glimmer.js +8534 -0
- data/vendor/prettier/plugins/glimmer.mjs +8421 -0
- data/vendor/prettier/plugins/graphql.d.ts +5 -0
- data/vendor/prettier/plugins/graphql.js +2421 -0
- data/vendor/prettier/plugins/graphql.mjs +2347 -0
- data/vendor/prettier/plugins/html.d.ts +8 -0
- data/vendor/prettier/plugins/html.js +8182 -0
- data/vendor/prettier/plugins/html.mjs +8077 -0
- data/vendor/prettier/plugins/markdown.d.ts +7 -0
- data/vendor/prettier/plugins/markdown.js +9068 -0
- data/vendor/prettier/plugins/markdown.mjs +8977 -0
- data/vendor/prettier/plugins/meriyah.d.ts +5 -0
- data/vendor/prettier/plugins/meriyah.js +5953 -0
- data/vendor/prettier/plugins/meriyah.mjs +5800 -0
- data/vendor/prettier/plugins/postcss.d.ts +7 -0
- data/vendor/prettier/plugins/postcss.js +9244 -0
- data/vendor/prettier/plugins/postcss.mjs +9046 -0
- data/vendor/prettier/plugins/typescript.d.ts +5 -0
- data/vendor/prettier/plugins/typescript.js +38058 -0
- data/vendor/prettier/plugins/typescript.mjs +37732 -0
- data/vendor/prettier/plugins/yaml.d.ts +5 -0
- data/vendor/prettier/plugins/yaml.js +7425 -0
- data/vendor/prettier/plugins/yaml.mjs +7329 -0
- data/vendor/prettier/standalone.d.ts +33 -0
- data/vendor/prettier/standalone.js +3984 -0
- data/vendor/prettier/standalone.mjs +3938 -0
- data/vendor/sql-formatter.js +18762 -0
- metadata +205 -2
data/package-lock.json
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
{
|
2
|
+
"name": "dorian",
|
3
|
+
"lockfileVersion": 3,
|
4
|
+
"requires": true,
|
5
|
+
"packages": {
|
6
|
+
"": {
|
7
|
+
"license": "MIT",
|
8
|
+
"dependencies": {
|
9
|
+
"groovy-beautify": "*",
|
10
|
+
"prettier": "*"
|
11
|
+
},
|
12
|
+
"engines": {
|
13
|
+
"node": "22.5.1",
|
14
|
+
"npm": "10.8.2"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
"node_modules/groovy-beautify": {
|
18
|
+
"version": "0.0.17",
|
19
|
+
"resolved": "https://registry.npmjs.org/groovy-beautify/-/groovy-beautify-0.0.17.tgz",
|
20
|
+
"integrity": "sha512-n3GRn7wJMCoPpNOC9bhuHWxnTkb9CwVnQH1RJK4M/F3Edc7l2FOa7wLa8iL2eqt0sQgQLzbxSsvZ7En2fJ8ZUg==",
|
21
|
+
"license": "MIT"
|
22
|
+
},
|
23
|
+
"node_modules/prettier": {
|
24
|
+
"version": "3.3.3",
|
25
|
+
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz",
|
26
|
+
"integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==",
|
27
|
+
"license": "MIT",
|
28
|
+
"bin": {
|
29
|
+
"prettier": "bin/prettier.cjs"
|
30
|
+
},
|
31
|
+
"engines": {
|
32
|
+
"node": ">=14"
|
33
|
+
},
|
34
|
+
"funding": {
|
35
|
+
"url": "https://github.com/prettier/prettier?sponsor=1"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
data/package.json
ADDED
data/samples/books.json
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"author": "F. Scott Fitzgerald",
|
4
|
+
"available": true,
|
5
|
+
"genres": [
|
6
|
+
"Novel",
|
7
|
+
"Historical"
|
8
|
+
],
|
9
|
+
"published_year": 1925,
|
10
|
+
"title": "The Great Gatsby"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"author": "Harper Lee",
|
14
|
+
"available": false,
|
15
|
+
"genres": [
|
16
|
+
"Novel",
|
17
|
+
"Southern Gothic",
|
18
|
+
"Bildungsroman"
|
19
|
+
],
|
20
|
+
"published_year": 1960,
|
21
|
+
"title": "To Kill a Mockingbird"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"author": "George Orwell",
|
25
|
+
"available": true,
|
26
|
+
"genres": [
|
27
|
+
"Dystopian",
|
28
|
+
"Political Fiction"
|
29
|
+
],
|
30
|
+
"published_year": 1949,
|
31
|
+
"title": "1984"
|
32
|
+
}
|
33
|
+
]
|
data/samples/books.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
{"title":"The Great Gatsby","author":"F. Scott Fitzgerald","published_year":1925,"genres":["Novel","Historical"],"available":true}
|
2
|
+
{"title":"To Kill a Mockingbird","author":"Harper Lee","published_year":1960,"genres":["Novel","Southern Gothic","Bildungsroman"],"available":false}
|
3
|
+
{"title":"1984","author":"George Orwell","published_year":1949,"genres":["Dystopian","Political Fiction"],"available":true}
|
data/samples/config.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
allowed_hosts:
|
3
|
+
- localhost
|
4
|
+
- example.com
|
5
|
+
- api.example.com
|
6
|
+
app_config:
|
7
|
+
debug_mode: false
|
8
|
+
environment: production
|
9
|
+
name: My Web App
|
10
|
+
version: 1.0.0
|
11
|
+
database:
|
12
|
+
host: localhost
|
13
|
+
name: my_web_app_db
|
14
|
+
password: securepassword
|
15
|
+
port: 5432
|
16
|
+
username: db_user
|
17
|
+
features:
|
18
|
+
api: true
|
19
|
+
authentication: true
|
20
|
+
web_sockets: false
|
21
|
+
logging:
|
22
|
+
file_path: "/var/log/my_web_app.log"
|
23
|
+
level: info
|
24
|
+
log_to_file: true
|
25
|
+
server:
|
26
|
+
host: 0.0.0.0
|
27
|
+
port: 8080
|
@@ -0,0 +1,22 @@
|
|
1
|
+
---
|
2
|
+
allowed_hosts:
|
3
|
+
- example.com
|
4
|
+
- api.example.com
|
5
|
+
app_config:
|
6
|
+
debug_mode: false
|
7
|
+
environment: production
|
8
|
+
name: My Web App
|
9
|
+
version: 1.0.0
|
10
|
+
database:
|
11
|
+
host: localhost
|
12
|
+
name: my_web_app_db
|
13
|
+
port: 5432
|
14
|
+
username: db_user
|
15
|
+
features:
|
16
|
+
api: true
|
17
|
+
authentication: true
|
18
|
+
web_sockets: false
|
19
|
+
logging:
|
20
|
+
file_path: "/var/log/my_web_app.log"
|
21
|
+
level: info
|
22
|
+
log_to_file: true
|
data/samples/maths.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1 + 1;
|
data/samples/numbers.raw
ADDED
data/samples/people.csv
ADDED
data/samples/people.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
---
|
2
|
+
- department: Engineering
|
3
|
+
full_time: true
|
4
|
+
id: 101
|
5
|
+
name: Alice Johnson
|
6
|
+
role: Software Engineer
|
7
|
+
skills:
|
8
|
+
- Python
|
9
|
+
- Ruby
|
10
|
+
- JavaScript
|
11
|
+
- department: Marketing
|
12
|
+
full_time: false
|
13
|
+
id: 102
|
14
|
+
name: Bob Smith
|
15
|
+
role: Marketing Specialist
|
16
|
+
skills:
|
17
|
+
- SEO
|
18
|
+
- Content Writing
|
19
|
+
- Social Media
|
20
|
+
- department: Human Resources
|
21
|
+
full_time: true
|
22
|
+
id: 103
|
23
|
+
name: Charlie Brown
|
24
|
+
role: HR Manager
|
25
|
+
skills:
|
26
|
+
- Recruitment
|
27
|
+
- Employee Relations
|
28
|
+
- Compliance
|
data/samples/query.sql
ADDED
data/samples/user.json
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"user": {
|
3
|
+
"account_created": "2021-05-20T14:30:00Z",
|
4
|
+
"address": {
|
5
|
+
"city": "Anytown",
|
6
|
+
"state": "CA",
|
7
|
+
"street": "123 Main St",
|
8
|
+
"zip_code": "12345"
|
9
|
+
},
|
10
|
+
"email": "john.doe@example.com",
|
11
|
+
"id": 12345,
|
12
|
+
"is_active": true,
|
13
|
+
"name": "John Doe",
|
14
|
+
"preferences": {
|
15
|
+
"newsletter": true,
|
16
|
+
"notifications": {
|
17
|
+
"email": true,
|
18
|
+
"sms": false
|
19
|
+
}
|
20
|
+
},
|
21
|
+
"profile": {
|
22
|
+
"age": 30,
|
23
|
+
"gender": "male",
|
24
|
+
"interests": [
|
25
|
+
"reading",
|
26
|
+
"coding",
|
27
|
+
"hiking"
|
28
|
+
]
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
data/spec/dorian_spec.rb
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "json"
|
5
|
+
require "yaml"
|
6
|
+
require "csv"
|
7
|
+
|
8
|
+
RSpec.describe "Dorian" do
|
9
|
+
describe "--version" do
|
10
|
+
it "works" do
|
11
|
+
version = File.read("VERSION")
|
12
|
+
expect(`bin/dorian -v 2>&1`).to eq(version)
|
13
|
+
expect(`bin/dorian --version 2>&1`).to eq(version)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "--help" do
|
18
|
+
it "works" do
|
19
|
+
expect(`bin/dorian -h 2>&1`).to include("USAGE")
|
20
|
+
expect(`bin/dorian --help 2>&1`).to include("USAGE")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "read" do
|
25
|
+
it "works" do
|
26
|
+
books_original = File.read("samples/books.json")
|
27
|
+
books = JSON.parse(books_original)
|
28
|
+
books_pretty = "#{JSON.pretty_generate(books)}\n"
|
29
|
+
books_ugly = "#{books.to_json}\n"
|
30
|
+
books_yaml = books.to_yaml
|
31
|
+
books_csv =
|
32
|
+
CSV.generate(headers: books.first.keys) do |csv|
|
33
|
+
csv << books.first.keys
|
34
|
+
|
35
|
+
books.each { |book| csv << book }
|
36
|
+
end
|
37
|
+
|
38
|
+
books_headers = books_csv.lines[0]
|
39
|
+
books_first_line = books_csv.lines[1]
|
40
|
+
|
41
|
+
expect(`bin/dorian samples/books.json`).to eq(books_pretty)
|
42
|
+
expect(`bin/dorian -io raw samples/books.json`).to eq(books_original)
|
43
|
+
expect(`bin/dorian --input raw --output raw samples/books.json`).to eq(
|
44
|
+
books_original
|
45
|
+
)
|
46
|
+
expect(`bin/dorian --pretty samples/books.json`).to eq(books_pretty)
|
47
|
+
expect(`bin/dorian --pretty true samples/books.json`).to eq(books_pretty)
|
48
|
+
expect(`bin/dorian --pretty false samples/books.json`).to eq(books_ugly)
|
49
|
+
expect(`bin/dorian --input json samples/books.json`).to eq(books_pretty)
|
50
|
+
expect(`bin/dorian --io json samples/books.json`).to eq(books_pretty)
|
51
|
+
expect(`bin/dorian --output yaml samples/books.json`).to eq(books_yaml)
|
52
|
+
expect(`bin/dorian --output csv samples/books.json`).to eq(books_csv)
|
53
|
+
expect(`bin/dorian -p samples/books.json`).to eq(books_pretty)
|
54
|
+
expect(`bin/dorian -p --pretty samples/books.json`).to eq(books_pretty)
|
55
|
+
expect(`bin/dorian -p --pretty true samples/books.json`).to eq(
|
56
|
+
books_pretty
|
57
|
+
)
|
58
|
+
expect(`bin/dorian -p --pretty false samples/books.json`).to eq(
|
59
|
+
books_ugly
|
60
|
+
)
|
61
|
+
expect(`bin/dorian -p --input json samples/books.json`).to eq(
|
62
|
+
books_pretty
|
63
|
+
)
|
64
|
+
expect(`bin/dorian -p --io json samples/books.json`).to eq(books_pretty)
|
65
|
+
expect(`bin/dorian -p --output yaml samples/books.json`).to eq(books_yaml)
|
66
|
+
expect(`bin/dorian -p --output csv samples/books.json`).to include(
|
67
|
+
books_headers
|
68
|
+
)
|
69
|
+
expect(`bin/dorian -p --output csv samples/books.json`).to include(
|
70
|
+
books_first_line
|
71
|
+
)
|
72
|
+
expect(`bin/dorian read samples/books.json`).to eq(books_pretty)
|
73
|
+
expect(`bin/dorian read -io raw samples/books.json`).to eq(books_original)
|
74
|
+
expect(
|
75
|
+
`bin/dorian read --input raw --output raw samples/books.json`
|
76
|
+
).to eq(books_original)
|
77
|
+
expect(`bin/dorian read --pretty samples/books.json`).to eq(books_pretty)
|
78
|
+
expect(`bin/dorian read --pretty true samples/books.json`).to eq(
|
79
|
+
books_pretty
|
80
|
+
)
|
81
|
+
expect(`bin/dorian read --pretty false samples/books.json`).to eq(
|
82
|
+
books_ugly
|
83
|
+
)
|
84
|
+
expect(`bin/dorian read --input json samples/books.json`).to eq(
|
85
|
+
books_pretty
|
86
|
+
)
|
87
|
+
expect(`bin/dorian read --io json samples/books.json`).to eq(books_pretty)
|
88
|
+
expect(`bin/dorian read --output yaml samples/books.json`).to eq(
|
89
|
+
books_yaml
|
90
|
+
)
|
91
|
+
expect(`bin/dorian read --output csv samples/books.json`).to eq(books_csv)
|
92
|
+
expect(`bin/dorian read -p samples/books.json`).to eq(books_pretty)
|
93
|
+
expect(`bin/dorian read -p --pretty samples/books.json`).to eq(
|
94
|
+
books_pretty
|
95
|
+
)
|
96
|
+
expect(`bin/dorian read -p --pretty true samples/books.json`).to eq(
|
97
|
+
books_pretty
|
98
|
+
)
|
99
|
+
expect(`bin/dorian read -p --pretty false samples/books.json`).to eq(
|
100
|
+
books_ugly
|
101
|
+
)
|
102
|
+
expect(`bin/dorian read -p --input json samples/books.json`).to eq(
|
103
|
+
books_pretty
|
104
|
+
)
|
105
|
+
expect(`bin/dorian read -p --io json samples/books.json`).to eq(
|
106
|
+
books_pretty
|
107
|
+
)
|
108
|
+
expect(`bin/dorian read -p --output yaml samples/books.json`).to eq(
|
109
|
+
books_yaml
|
110
|
+
)
|
111
|
+
expect(`bin/dorian read -p --output csv samples/books.json`).to include(
|
112
|
+
books_headers
|
113
|
+
)
|
114
|
+
expect(`bin/dorian read -p --output csv samples/books.json`).to include(
|
115
|
+
books_first_line
|
116
|
+
)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "all" do
|
121
|
+
it "works" do
|
122
|
+
input = "echo [1, 2, 3]"
|
123
|
+
command = "bin/dorian all --io json"
|
124
|
+
input_command = "#{input} | #{command}"
|
125
|
+
expect(`#{input_command} "p it.first"`).to eq("1\n")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "after" do
|
130
|
+
it "works" do
|
131
|
+
input = "cat samples/numbers.raw"
|
132
|
+
command = "bin/dorian after"
|
133
|
+
input_command = "#{input} | #{command}"
|
134
|
+
expect(`#{input_command} "it.to_i == 8"`).to eq(<<~OUTPUT)
|
135
|
+
8
|
136
|
+
9
|
137
|
+
10
|
138
|
+
OUTPUT
|
139
|
+
expect(`#{input_command} 7`).to eq(<<~OUTPUT)
|
140
|
+
8
|
141
|
+
9
|
142
|
+
10
|
143
|
+
OUTPUT
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "before" do
|
148
|
+
it "works" do
|
149
|
+
input = "cat samples/numbers.raw"
|
150
|
+
command = "bin/dorian before"
|
151
|
+
input_command = "#{input} | #{command}"
|
152
|
+
expect(`#{input_command} "it.to_i == 3"`).to eq(<<~OUTPUT)
|
153
|
+
1
|
154
|
+
2
|
155
|
+
3
|
156
|
+
OUTPUT
|
157
|
+
expect(`#{input_command} 2`).to eq(<<~OUTPUT)
|
158
|
+
1
|
159
|
+
2
|
160
|
+
3
|
161
|
+
OUTPUT
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "between" do
|
166
|
+
it "works" do
|
167
|
+
input = "cat samples/numbers.raw"
|
168
|
+
command = "bin/dorian between"
|
169
|
+
input_command = "#{input} | #{command}"
|
170
|
+
expect(`#{input_command} "it.to_i == 3" "it.to_i == 5"`).to eq(<<~OUTPUT)
|
171
|
+
3
|
172
|
+
4
|
173
|
+
5
|
174
|
+
OUTPUT
|
175
|
+
expect(`#{input_command} 2 4`).to eq(<<~OUTPUT)
|
176
|
+
3
|
177
|
+
4
|
178
|
+
5
|
179
|
+
OUTPUT
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "tally" do
|
184
|
+
it "works" do
|
185
|
+
input = "cat samples/numbers.raw"
|
186
|
+
command = "bin/dorian tally"
|
187
|
+
input_command = "#{input} | #{command}"
|
188
|
+
expect(`#{input_command} "it.to_i > 2"`).to eq(<<~OUTPUT)
|
189
|
+
{
|
190
|
+
"false": 2,
|
191
|
+
"true": 8
|
192
|
+
}
|
193
|
+
OUTPUT
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "select" do
|
198
|
+
it "works" do
|
199
|
+
input = "cat samples/numbers.raw"
|
200
|
+
command = "bin/dorian select"
|
201
|
+
input_command = "#{input} | #{command}"
|
202
|
+
expect(`#{input_command} "it.to_i.even?"`).to eq(<<~OUTPUT)
|
203
|
+
2
|
204
|
+
4
|
205
|
+
6
|
206
|
+
8
|
207
|
+
10
|
208
|
+
OUTPUT
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "reject" do
|
213
|
+
it "works" do
|
214
|
+
input = "cat samples/numbers.raw"
|
215
|
+
command = "bin/dorian reject"
|
216
|
+
input_command = "#{input} | #{command}"
|
217
|
+
expect(`#{input_command} "it.to_i.even?"`).to eq(<<~OUTPUT)
|
218
|
+
1
|
219
|
+
3
|
220
|
+
5
|
221
|
+
7
|
222
|
+
9
|
223
|
+
OUTPUT
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "each" do
|
228
|
+
it "works" do
|
229
|
+
input = "echo [1, 2, 3]"
|
230
|
+
command = "bin/dorian each --io json --parallel false --fast false"
|
231
|
+
input_command = "#{input} | #{command}"
|
232
|
+
expect(`#{input_command} "p it"`).to eq(<<~OUTPUT)
|
233
|
+
1
|
234
|
+
2
|
235
|
+
3
|
236
|
+
OUTPUT
|
237
|
+
expect(`#{input_command} -deep "p it"`).to eq(<<~OUTPUT)
|
238
|
+
[1, 2, 3]
|
239
|
+
1
|
240
|
+
2
|
241
|
+
3
|
242
|
+
OUTPUT
|
243
|
+
expect(`#{input_command} --debug "p it"`).to eq(<<~OUTPUT)
|
244
|
+
[1] 1
|
245
|
+
[2] 2
|
246
|
+
[3] 3
|
247
|
+
OUTPUT
|
248
|
+
expect(`#{input_command} -deep --debug "p it"`).to eq(<<~OUTPUT)
|
249
|
+
[[1, 2, 3]] [1, 2, 3]
|
250
|
+
[1] 1
|
251
|
+
[2] 2
|
252
|
+
[3] 3
|
253
|
+
OUTPUT
|
254
|
+
expect(`#{input_command} --stdout false "p it"`).to eq("")
|
255
|
+
expect(`#{input_command} --stdout false -deep "p it"`).to eq("")
|
256
|
+
expect(`#{input_command} --stdout false --debug "p it"`).to eq("")
|
257
|
+
expect(`#{input_command} --stdout false -deep --debug "p it"`).to eq("")
|
258
|
+
expect(`#{input_command} --parallel "p it"`).to include("1")
|
259
|
+
expect(`#{input_command} --parallel -deep "p it"`).to include("1")
|
260
|
+
expect(`#{input_command} --parallel --debug "p it"`).to include("[1] 1")
|
261
|
+
expect(`#{input_command} --parallel -deep --debug "p it"`).to include(
|
262
|
+
"[1] 1"
|
263
|
+
)
|
264
|
+
expect(`#{input_command} --parallel --stdout false "p it"`).to eq("")
|
265
|
+
expect(`#{input_command} --parallel --stdout false -deep "p it"`).to eq(
|
266
|
+
""
|
267
|
+
)
|
268
|
+
expect(`#{input_command} --parallel --stdout false --debug "p it"`).to eq(
|
269
|
+
""
|
270
|
+
)
|
271
|
+
expect(
|
272
|
+
`#{input_command} --parallel --stdout false -deep --debug "p it"`
|
273
|
+
).to eq("")
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Sergei Kasoverskij
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# groovy-beautify
|
2
|
+
|
3
|
+
A simple zero-dependency beautifier which allows formatting and indenting Groovy scripts
|
4
|
+
|
5
|
+
# Demo
|
6
|
+
|
7
|
+
You can test how it works on the [Demo Website](https://groovy-beautify-web.vercel.app/)
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
npm install groovy-beautify
|
12
|
+
|
13
|
+
# Usage
|
14
|
+
|
15
|
+
import groovyBeautify from "groovy-beautify";
|
16
|
+
|
17
|
+
const groovy = `
|
18
|
+
def bumpVersion(String target, String version_type, Boolean reset = false) { def
|
19
|
+
versionMap =
|
20
|
+
['major':0, 'minor' : 1, 'patch': 2]
|
21
|
+
def versionArray = target.findAll(/\d+\.\d+\.\d+/)[0].tokenize('.')
|
22
|
+
try
|
23
|
+
{ def index = versionMap.get(version_type);
|
24
|
+
versionArray[index] =versionArray[index].toInteger() + 1
|
25
|
+
if( reset )
|
26
|
+
{
|
27
|
+
for(int i=2;i>index; i--) {
|
28
|
+
versionArray[i] = 0 } }
|
29
|
+
} catch( Exception e) { println("Unrecognized version type \\"version_type\\" (should be major, minor or patch)") }
|
30
|
+
return versionArray.join( '.' )
|
31
|
+
}
|
32
|
+
println(bumpVersion('1.2.3', 'minor', true))
|
33
|
+
`;
|
34
|
+
|
35
|
+
const formatted = groovyBeautify(groovy);
|
36
|
+
|
37
|
+
This will produce the following output
|
38
|
+
|
39
|
+
def bumpVersion(String target, String version_type, Boolean reset = false) {
|
40
|
+
def versionMap = ['major': 0, 'minor': 1, 'patch': 2]
|
41
|
+
def versionArray = target.findAll(/d+.d+.d+/)[0].tokenize('.')
|
42
|
+
try {
|
43
|
+
def index = versionMap.get(version_type);
|
44
|
+
versionArray[index] = versionArray[index].toInteger() + 1
|
45
|
+
if (reset)
|
46
|
+
{
|
47
|
+
for (int i = 2; i > index; i--) {
|
48
|
+
versionArray[i] = 0
|
49
|
+
}
|
50
|
+
}
|
51
|
+
} catch (Exception e) {
|
52
|
+
println("Unrecognized version type \"version_type\" (should be major, minor or patch)")
|
53
|
+
}
|
54
|
+
return versionArray.join('.')
|
55
|
+
}
|
56
|
+
|
57
|
+
println(bumpVersion('1.2.3', 'minor', true))
|
58
|
+
|
59
|
+
# License
|
60
|
+
|
61
|
+
You are free to use this in any way you want, in case you find this useful or working for you but you must keep the copyright notice and license. (MIT)
|
62
|
+
|
63
|
+
# Credits
|
64
|
+
|
65
|
+
- Created by Sergei Kasoverskij, <joycollector@gmail.com>
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|