sord 0.10.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- data/.github/ISSUE_TEMPLATE/feature-request.md +0 -0
- data/.gitignore +0 -0
- data/.parlour +6 -2
- data/.rspec +0 -0
- data/.travis.yml +0 -0
- data/CHANGELOG.md +68 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +72 -44
- data/Rakefile +26 -7
- data/exe/sord +46 -6
- data/lib/sord.rb +1 -1
- data/lib/sord/generator.rb +592 -0
- data/lib/sord/logging.rb +0 -0
- data/lib/sord/parlour_plugin.rb +23 -2
- data/lib/sord/resolver.rb +0 -0
- data/lib/sord/type_converter.rb +71 -63
- data/lib/sord/version.rb +1 -1
- data/rbi/sord.rbi +211 -30
- data/sord.gemspec +3 -3
- metadata +11 -30
- data/lib/sord/rbi_generator.rb +0 -391
- data/sorbet/config +0 -0
- data/sorbet/rbi/gems/docile.rbi +0 -31
- data/sorbet/rbi/gems/parlour.rbi +0 -214
- data/sorbet/rbi/gems/rainbow.rbi +0 -117
- data/sorbet/rbi/gems/rake.rbi +0 -643
- data/sorbet/rbi/gems/rspec-core.rbi +0 -1658
- data/sorbet/rbi/gems/rspec-expectations.rbi +0 -389
- data/sorbet/rbi/gems/rspec-mocks.rbi +0 -823
- data/sorbet/rbi/gems/rspec-support.rbi +0 -268
- data/sorbet/rbi/gems/rspec.rbi +0 -14
- data/sorbet/rbi/gems/simplecov-html.rbi +0 -30
- data/sorbet/rbi/gems/simplecov.rbi +0 -225
- data/sorbet/rbi/gems/sorbet-runtime.rbi +0 -670
- data/sorbet/rbi/gems/yard.rbi +0 -310
- data/sorbet/rbi/hidden-definitions/errors.txt +0 -9285
- data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -26604
- data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +0 -8575
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +0 -111
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +0 -543
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fce2fcb8629a399513abe70e01d8175fe57932cea68f3183efaaf5475b1d2a1
|
4
|
+
data.tar.gz: b47e6015b205134fb8687d8a81a1174978ed075fc66dcfd0574475756373abbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e156fa5ee965a1def468b67a9a1945f6d5fb164b0c756b8c3813a99fc12438404b65976842f34e5806d90a6493c553491d87d3272abcd8703436457691d60c8e
|
7
|
+
data.tar.gz: 004b7eab6b52fa397cded80d1960b91aef104689d1567722de17fc116116998508c83faef5cb32fecc262ec80b1663d4f9d6601defb78fcf5c4ed233403189f6
|
File without changes
|
File without changes
|
data/.gitignore
CHANGED
File without changes
|
data/.parlour
CHANGED
data/.rspec
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,74 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
5
5
|
|
6
|
+
## [3.0.0] - 2020-12-26
|
7
|
+
### Added
|
8
|
+
- Sord now uses the Parlour 5 beta's RBS generation to generate RBS files!
|
9
|
+
- Added `--rbi` and `--rbs` to select an output format to use (if neither given,
|
10
|
+
tries to infer from file extension).
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- `RbiGenerator` has been renamed to `Generator`.
|
14
|
+
- `TypeConverter#yard_to_sorbet` is now `TypeConverter#yard_to_parlour`, and
|
15
|
+
returns `Parlour::Types::Type` instances rather than strings.
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
- `#return [nil]` no longer produces a union of zero types, instead becoming
|
19
|
+
`void` for method returns or `untyped` for attributes.
|
20
|
+
|
21
|
+
|
22
|
+
<details>
|
23
|
+
<summary>3.0.0 pre-releases</summary>
|
24
|
+
|
25
|
+
## [3.0.0.beta.2] - 2020-10-05
|
26
|
+
### Added
|
27
|
+
- Sord is no longer limited to a known set of generics, and will instead
|
28
|
+
generate `Parlour::Types::Generic` types for user-defined generics.
|
29
|
+
|
30
|
+
## [3.0.0.beta.1] - 2020-09-16
|
31
|
+
### Added
|
32
|
+
- Sord now uses the Parlour 5 beta's RBS generation to generate RBS files!
|
33
|
+
- Added `--rbi` and `--rbs` to select an output format to use (if neither given,
|
34
|
+
tries to infer from file extension).
|
35
|
+
|
36
|
+
### Changed
|
37
|
+
- `RbiGenerator` has been renamed to `Generator`.
|
38
|
+
- `TypeConverter#yard_to_sorbet` is now `TypeConverter#yard_to_parlour`, and
|
39
|
+
returns `Parlour::Types::Type` instances rather than strings.
|
40
|
+
|
41
|
+
### Fixed
|
42
|
+
- `#return [nil]` no longer produces a union of zero types, instead becoming
|
43
|
+
`void` for method returns or `untyped` for attributes.
|
44
|
+
|
45
|
+
</details>
|
46
|
+
|
47
|
+
## [2.0.0] - 2020-03-16
|
48
|
+
### Added
|
49
|
+
- Sord now supports generating `attr_accessor`, `attr_reader` and `attr_writer`
|
50
|
+
and will do so automatically when these are used in your code.
|
51
|
+
- Depending on what you're doing with Sord, this is **potentially breaking**,
|
52
|
+
as for example attributes which would previously generate two `foo` and `foo=`
|
53
|
+
methods in Sord will now just generate an `attr_accessor`.
|
54
|
+
- `#initialize` is now always typed as returning `void`, which is
|
55
|
+
**potentially breaking** if you directly call `#initialize` in code.
|
56
|
+
- The `--use-original-initialize-return` flag restores the old behaviour of
|
57
|
+
using whatever return type is provided, like any other method.
|
58
|
+
|
59
|
+
## [1.0.0] - 2020-02-16
|
60
|
+
### Added
|
61
|
+
- Added the `--skip-constants` flag to avoid generating RBIs for constants.
|
62
|
+
|
63
|
+
### Changed
|
64
|
+
- Parlour 2.0.0 is now being used.
|
65
|
+
|
66
|
+
### Fixed
|
67
|
+
- Fixed a bug where blank parameters were sometimes treated like non-blank
|
68
|
+
parameters.
|
69
|
+
- Fixed parameter order sometimes being incorrect.
|
70
|
+
- Fixed multiline parameter lists sometimes generating invalid RBIs.
|
71
|
+
- Multiline comments are now generated correctly.
|
72
|
+
- Fixed an incorrect README link.
|
73
|
+
|
6
74
|
## [0.10.0] - 2019-09-14
|
7
75
|
### Added
|
8
76
|
- Comments in RBIs are now converted from YARD into Markdown format, making them
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -2,25 +2,28 @@
|
|
2
2
|
|
3
3
|
## Overview
|
4
4
|
|
5
|
-
Sord is a [**So**rbet](https://sorbet.org) and [YA**RD**](https://
|
6
|
-
crossover. It can automatically generate
|
7
|
-
looking at the types specified in YARD documentation comments.
|
5
|
+
Sord is a [**So**rbet](https://sorbet.org) and [YA**RD**](https://yardoc.org/)
|
6
|
+
crossover. It can **automatically generate RBI and RBS type signature files** by
|
7
|
+
looking at the **types specified in YARD documentation** comments.
|
8
8
|
|
9
9
|
If your project is already YARD documented, then this can generate most of the
|
10
|
-
|
10
|
+
type signatures you need!
|
11
|
+
|
12
|
+
Sord is the perfect way to jump-start the adoption of types in your project,
|
13
|
+
whether you plan to use Sorbet's RBI format or Ruby 3/Steep's RBS format.
|
11
14
|
|
12
15
|
Sord has the following features:
|
13
16
|
- Automatically generates signatures for modules, classes and methods
|
14
|
-
- Support for multiple parameter or return types (`T.any
|
15
|
-
- Gracefully handles missing YARD types (`T.untyped`)
|
17
|
+
- Support for multiple parameter or return types (`T.any`/`|`)
|
18
|
+
- Gracefully handles missing YARD types (`T.untyped`/`untyped`)
|
16
19
|
- Can infer setter parameter type from the corresponding getter's return type
|
17
20
|
- Recognises mixins (`include` and `extend`)
|
18
21
|
- Support for generic types such as `Array<T>` and `Hash<K, V>`
|
19
22
|
- Can infer namespaced classes (`[Bar]` can become `GemName::Foo::Bar`)
|
20
|
-
- Handles return types which can be `nil` (`T.nilable`)
|
21
|
-
- Handles duck types (`T.untyped`)
|
23
|
+
- Handles return types which can be `nil` (`T.nilable`/`untyped`)
|
24
|
+
- Handles duck types (`T.untyped`/`untyped`)
|
22
25
|
- Support for ordered list types (`[Array(Integer, Symbol)]` becomes `[Integer, Symbol]`)
|
23
|
-
- Support for boolean types (`[true, false]` becomes `T::Boolean`)
|
26
|
+
- Support for boolean types (`[true, false]` becomes `T::Boolean`/`bool`)
|
24
27
|
- Support for `&block` parameters documented with `@yieldparam` and `@yieldreturn`
|
25
28
|
|
26
29
|
## Usage
|
@@ -29,7 +32,7 @@ Install Sord with `gem install sord`.
|
|
29
32
|
|
30
33
|
Sord is a command line tool. To use it, open a terminal in the root directory
|
31
34
|
of your project and invoke `sord`, passing a path where you'd like to save your
|
32
|
-
|
35
|
+
file (this file will be overwritten):
|
33
36
|
|
34
37
|
```
|
35
38
|
sord defs.rbi
|
@@ -37,7 +40,12 @@ sord defs.rbi
|
|
37
40
|
|
38
41
|
Sord will generate YARD docs and then print information about what it's inferred
|
39
42
|
as it runs. It is best to fix any issues in the YARD documentation, as any edits
|
40
|
-
made to the resulting
|
43
|
+
made to the resulting file will be replaced if you re-run Sord.
|
44
|
+
|
45
|
+
The output type is inferred by the file extension you use, but you can also
|
46
|
+
specify it explicitly with `--rbi` or `--rbs`.
|
47
|
+
|
48
|
+
## Shipping RBI Types
|
41
49
|
|
42
50
|
RBI files generated by Sord can be used in two main ways:
|
43
51
|
|
@@ -50,18 +58,22 @@ where the maintainer is unwilling to ship type signatures with the gem itself.
|
|
50
58
|
|
51
59
|
### Flags
|
52
60
|
|
53
|
-
Sord also takes some flags to alter the generated
|
61
|
+
Sord also takes some flags to alter the generated file:
|
54
62
|
|
55
|
-
- `--
|
56
|
-
|
57
|
-
|
63
|
+
- `--rbi`/`--rbs`: Override the output format inferred from the file
|
64
|
+
extension.
|
65
|
+
- `--no-sord-comments`: Generates the file without any Sord comments about
|
66
|
+
warnings/inferences/errors. (The original file's comments will still be
|
67
|
+
included.)
|
58
68
|
- `--no-regenerate`: By default, Sord will regenerate a repository's YARD
|
59
69
|
docs for you. This option skips regenerating the YARD docs.
|
60
70
|
- `--break-params`: Determines how many parameters are necessary before
|
61
71
|
the signature is changed from a single-line to a multi-line block.
|
62
72
|
(Default: 4)
|
63
|
-
- `--replace-errors-with-untyped`: Uses `T.untyped` instead of `SORD_ERROR_*`
|
64
|
-
|
73
|
+
- `--replace-errors-with-untyped`: Uses `T.untyped` instead of `SORD_ERROR_*`
|
74
|
+
constants.
|
75
|
+
- `--replace-unresolved-with-untyped`: Uses `T.untyped` when Sord is unable to
|
76
|
+
resolve a constant.
|
65
77
|
- `--include-messages` and `--exclude-messages`: Used to filter the logging
|
66
78
|
messages given by Sord. `--include-messages` acts as a whitelist, printing
|
67
79
|
only messages of the specified logging kinds, whereas `--exclude-messages`
|
@@ -85,10 +97,10 @@ module Example
|
|
85
97
|
@age = age
|
86
98
|
end
|
87
99
|
|
88
|
-
# @return
|
100
|
+
# @return [String]
|
89
101
|
attr_accessor :name
|
90
102
|
|
91
|
-
# @return
|
103
|
+
# @return [Integer]
|
92
104
|
attr_accessor :age
|
93
105
|
|
94
106
|
# @param possible_names [Array<String>] An array of potential names to choose from.
|
@@ -106,9 +118,8 @@ First, generate a YARD registry by running `yardoc test.rb`. Then, we can run
|
|
106
118
|
files! Note the `.rbi` file extension.) In doing this, Sord prints:
|
107
119
|
|
108
120
|
```
|
109
|
-
[INFER]
|
110
|
-
[
|
111
|
-
[DONE ] Processed 8 objects
|
121
|
+
[INFER] Assuming from filename you wish to generate in RBI format
|
122
|
+
[DONE ] Processed 8 objects (2 namespaces and 6 methods)
|
112
123
|
```
|
113
124
|
|
114
125
|
The `test.rbi` file then contains a complete RBI file for `test.rb`:
|
@@ -117,29 +128,45 @@ The `test.rbi` file then contains a complete RBI file for `test.rb`:
|
|
117
128
|
# typed: strong
|
118
129
|
module Example
|
119
130
|
class Person
|
120
|
-
# @
|
121
|
-
#
|
122
|
-
|
131
|
+
# _@param_ `name` — The name of the Person to create.
|
132
|
+
#
|
133
|
+
# _@param_ `age` — The age of the Person to create.
|
134
|
+
sig { params(name: String, age: Integer).void }
|
123
135
|
def initialize(name, age); end
|
124
136
|
|
125
|
-
|
126
|
-
|
137
|
+
# _@param_ `possible_names` — An array of potential names to choose from.
|
138
|
+
#
|
139
|
+
# _@param_ `possible_ages` — An array of potential ages to choose from.
|
140
|
+
sig { params(possible_names: T::Array[String], possible_ages: T::Array[Integer]).returns(Example::Person) }
|
141
|
+
def self.construct_randomly(possible_names, possible_ages); end
|
127
142
|
|
128
|
-
|
129
|
-
|
130
|
-
def name=(value); end
|
143
|
+
sig { returns(String) }
|
144
|
+
attr_accessor :name
|
131
145
|
|
132
146
|
sig { returns(Integer) }
|
133
|
-
|
147
|
+
attr_accessor :age
|
148
|
+
end
|
149
|
+
end
|
150
|
+
```
|
134
151
|
|
135
|
-
|
136
|
-
sig { params(value: Integer).returns(Integer) }
|
137
|
-
def age=(value); end
|
152
|
+
If we had instead generated `test.rbs`, we would get this file in RBS format:
|
138
153
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
154
|
+
```ruby
|
155
|
+
module Example
|
156
|
+
class Person
|
157
|
+
# _@param_ `name` — The name of the Person to create.
|
158
|
+
#
|
159
|
+
# _@param_ `age` — The age of the Person to create.
|
160
|
+
def initialize: (String name, Integer age) -> void
|
161
|
+
|
162
|
+
# _@param_ `possible_names` — An array of potential names to choose from.
|
163
|
+
#
|
164
|
+
# _@param_ `possible_ages` — An array of potential ages to choose from.
|
165
|
+
def self.construct_randomly: (Array[String] possible_names, Array[Integer] possible_ages) -> Example::Person
|
166
|
+
|
167
|
+
attr_accessor name: String
|
168
|
+
|
169
|
+
attr_accessor age: Integer
|
143
170
|
end
|
144
171
|
end
|
145
172
|
```
|
@@ -148,12 +175,13 @@ end
|
|
148
175
|
|
149
176
|
The general rule of thumb for type conversions is:
|
150
177
|
|
151
|
-
- If Sord understands the YARD type, then it is converted into the
|
178
|
+
- If Sord understands the YARD type, then it is converted into the RBI or RBS
|
179
|
+
type.
|
152
180
|
- If the YARD type is missing, Sord fills in `T.untyped`.
|
153
181
|
- If the YARD type can't be understood, Sord creates an undefined Ruby constant
|
154
182
|
with a similar name to the unknown YARD type. For example, the obviously
|
155
183
|
invalid YARD type `A%B` will become a constant called `SORD_ERROR_AB`.
|
156
|
-
You should search through your resulting
|
184
|
+
You should search through your resulting file to find and fix and
|
157
185
|
`SORD_ERROR`s.
|
158
186
|
|
159
187
|
## Contributing
|
@@ -161,11 +189,11 @@ The general rule of thumb for type conversions is:
|
|
161
189
|
Bug reports and pull requests are welcome on GitHub at https://github.com/AaronC81/sord. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
162
190
|
|
163
191
|
While contributing, if you want to see the results of your changes to Sord you
|
164
|
-
can use the `examples:seed` Rake task. The task uses Sord to generate
|
192
|
+
can use the `examples:seed` Rake task. The task uses Sord to generate types for
|
165
193
|
a number of open source Ruby gems, including Bundler, Haml, Rouge, and RSpec.
|
166
|
-
`rake examples:seed` (and `rake examples:reseed` to regenerate the
|
167
|
-
|
168
|
-
|
194
|
+
`rake examples:seed` (and `rake examples:reseed` to regenerate the files) will
|
195
|
+
clone the repositories of these gems into `sord_examples/` and then generate the
|
196
|
+
files into the same directory.
|
169
197
|
|
170
198
|
## License
|
171
199
|
|
data/Rakefile
CHANGED
@@ -10,6 +10,7 @@ REPOS = {
|
|
10
10
|
bundler: 'https://github.com/bundler/bundler',
|
11
11
|
discordrb: 'https://github.com/meew0/discordrb',
|
12
12
|
gitlab: 'https://github.com/NARKOZ/gitlab',
|
13
|
+
'graphql-ruby': 'https://github.com/rmosolgo/graphql-ruby',
|
13
14
|
haml: 'https://github.com/haml/haml',
|
14
15
|
oga: 'https://gitlab.com/yorickpeterse/oga',
|
15
16
|
rouge: 'https://github.com/rouge-ruby/rouge',
|
@@ -23,12 +24,21 @@ namespace :examples do
|
|
23
24
|
require 'rainbow'
|
24
25
|
|
25
26
|
desc "Clone git repositories and run Sord on them as examples"
|
26
|
-
task :seed, [:clean] do |t, args|
|
27
|
+
task :seed, [:mode, :clean] do |t, args|
|
27
28
|
if File.directory?('sord_examples')
|
28
29
|
puts Rainbow('sord_examples directory already exists, please delete the directory or run a reseed!').red
|
29
30
|
exit
|
30
31
|
end
|
31
32
|
|
33
|
+
if args[:mode] == 'rbi'
|
34
|
+
mode_arg = '--rbi'
|
35
|
+
elsif args[:mode] == 'rbs'
|
36
|
+
mode_arg = '--rbs'
|
37
|
+
else
|
38
|
+
puts Rainbow('please specify \'rbi\' or \'rbs\'!').red
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
32
42
|
FileUtils.mkdir 'sord_examples'
|
33
43
|
FileUtils.cd 'sord_examples'
|
34
44
|
|
@@ -45,11 +55,11 @@ namespace :examples do
|
|
45
55
|
# Generate sri
|
46
56
|
puts "Generating rbi for #{name}..."
|
47
57
|
if args[:clean]
|
48
|
-
system("bundle exec sord ../#{name}
|
58
|
+
system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg} --no-sord-comments --replace-errors-with-untyped --replace-unresolved-with-untyped")
|
49
59
|
else
|
50
|
-
system("bundle exec sord ../#{name}
|
60
|
+
system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg}")
|
51
61
|
end
|
52
|
-
puts "#{name}
|
62
|
+
puts "#{name}.#{args[:mode]} generated!"
|
53
63
|
FileUtils.cd '..'
|
54
64
|
end
|
55
65
|
end
|
@@ -58,21 +68,30 @@ namespace :examples do
|
|
58
68
|
end
|
59
69
|
|
60
70
|
desc 'Regenerate the rbi files in sord_examples.'
|
61
|
-
task :reseed, [:clean] do |t, args|
|
71
|
+
task :reseed, [:mode, :clean] do |t, args|
|
62
72
|
if Dir.exist?('sord_examples')
|
63
73
|
FileUtils.cd 'sord_examples'
|
64
74
|
else
|
65
75
|
raise Rainbow("The sord_examples directory does not exist. Have you run the seed task?").red.bold
|
66
76
|
end
|
67
77
|
|
78
|
+
if args[:mode] == 'rbi'
|
79
|
+
mode_arg = '--rbi'
|
80
|
+
elsif args[:mode] == 'rbs'
|
81
|
+
mode_arg = '--rbs'
|
82
|
+
else
|
83
|
+
puts Rainbow('please specify \'rbi\' or \'rbs\'!').red
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
|
68
87
|
REPOS.keys.each do |name|
|
69
88
|
FileUtils.cd name.to_s
|
70
89
|
puts "Regenerating rbi file for #{name}..."
|
71
90
|
Bundler.with_clean_env do
|
72
91
|
if args[:clean]
|
73
|
-
system("bundle exec sord ../#{name}
|
92
|
+
system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg} --no-regenerate --no-sord-comments --replace-errors-with-untyped --replace-unresolved-with-untyped")
|
74
93
|
else
|
75
|
-
system("bundle exec sord ../#{name}
|
94
|
+
system("bundle exec sord ../#{name}.#{args[:mode]} #{mode_arg} --no-regenerate")
|
76
95
|
end
|
77
96
|
end
|
78
97
|
FileUtils.cd '..'
|
data/exe/sord
CHANGED
@@ -10,8 +10,10 @@ program :description, 'Generate Sorbet RBIs from YARD documentation'
|
|
10
10
|
default_command :gen
|
11
11
|
command :gen do |c|
|
12
12
|
c.syntax = 'sord gen <output-file> [options]'
|
13
|
-
c.description = 'Generates
|
14
|
-
c.option '--
|
13
|
+
c.description = 'Generates a type signature file from this directory\'s YARD docs'
|
14
|
+
c.option '--rbi', 'Use Sorbet\'s RBI format'
|
15
|
+
c.option '--rbs', 'Use Steep/Ruby 3\'s RBS format'
|
16
|
+
c.option '--[no-]sord-comments', 'Controls informational/warning comments in the file'
|
15
17
|
c.option '--[no-]regenerate', 'Controls whether YARD is executed before Sord runs'
|
16
18
|
c.option '--break-params INTEGER', Integer, 'Break params onto their own lines if there are this many'
|
17
19
|
c.option '--replace-errors-with-untyped', 'Uses T.untyped rather than SORD_ERROR_ constants'
|
@@ -19,9 +21,13 @@ command :gen do |c|
|
|
19
21
|
c.option '--exclude-messages STRING', String, 'Blacklists a comma-separated string of log message types'
|
20
22
|
c.option '--include-messages STRING', String, 'Whitelists a comma-separated string of log message types'
|
21
23
|
c.option '--keep-original-comments', 'Retains original YARD comments rather than converting them to Markdown'
|
24
|
+
c.option '--skip-constants', 'Excludes constants from generated file'
|
25
|
+
c.option '--use-original-initialize-return', 'Uses the specified return type for #initialize rather than void'
|
22
26
|
|
23
27
|
c.action do |args, options|
|
24
28
|
options.default(
|
29
|
+
rbi: false,
|
30
|
+
rbs: false,
|
25
31
|
sord_comments: true,
|
26
32
|
regenerate: true,
|
27
33
|
break_params: 4,
|
@@ -29,22 +35,56 @@ command :gen do |c|
|
|
29
35
|
replace_unresolved_with_untyped: false,
|
30
36
|
exclude_messages: nil,
|
31
37
|
include_messages: nil,
|
32
|
-
keep_original_comments: false
|
38
|
+
keep_original_comments: false,
|
39
|
+
skip_constants: false,
|
40
|
+
use_original_initialize_return: false,
|
33
41
|
)
|
34
42
|
|
35
43
|
if args.length != 1
|
36
44
|
Sord::Logging.error('Must specify filename')
|
37
45
|
exit 1
|
38
46
|
end
|
39
|
-
|
47
|
+
|
40
48
|
plugin_options = options.__hash__
|
41
49
|
plugin_options[:exclude_options] = plugin_options[:exclude_options]&.split(',')
|
42
50
|
plugin_options[:include_options] = plugin_options[:include_options]&.split(',')
|
43
51
|
|
52
|
+
if !(plugin_options[:rbi] || plugin_options[:rbs])
|
53
|
+
if args.first
|
54
|
+
if args.first.end_with?('.rbi')
|
55
|
+
Sord::Logging.infer('Assuming from filename you wish to generate in RBI format')
|
56
|
+
plugin_options[:rbi] = true
|
57
|
+
elsif args.first.end_with?('.rbs')
|
58
|
+
Sord::Logging.infer('Assuming from filename you wish to generate in RBS format')
|
59
|
+
plugin_options[:rbs] = true
|
60
|
+
else
|
61
|
+
Sord::Logging.error('An output format could not be inferred from your filename; please specify --rbi or --rbs')
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
else
|
65
|
+
Sord::Logging.error('No output format given; please specify --rbi or --rbs')
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if (plugin_options[:rbi] && plugin_options[:rbs])
|
71
|
+
Sord::Logging.error('You cannot specify both --rbi and --rbs; please use only one')
|
72
|
+
exit 1
|
73
|
+
end
|
74
|
+
|
44
75
|
plugin = Sord::ParlourPlugin.new(plugin_options)
|
45
|
-
|
76
|
+
|
77
|
+
if plugin_options[:rbi]
|
78
|
+
klass = Parlour::RbiGenerator
|
79
|
+
generator_method = :rbi
|
80
|
+
elsif plugin_options[:rbs]
|
81
|
+
klass = Parlour::RbsGenerator
|
82
|
+
generator_method = :rbs
|
83
|
+
end
|
84
|
+
|
85
|
+
plugin.parlour = klass.new(break_params: plugin_options[:break_params])
|
46
86
|
plugin.generate(plugin.parlour.root)
|
47
87
|
|
48
|
-
File.write(args.first, plugin.parlour.
|
88
|
+
File.write(args.first, plugin.parlour.send(generator_method))
|
49
89
|
end
|
50
90
|
end
|