Skip to content

Commit 4eab1f1

Browse files
committed
adding version to cli
1 parent dbc8624 commit 4eab1f1

File tree

9 files changed

+37
-2
lines changed

9 files changed

+37
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/code_ownership/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rb-sys = { version = "0.9.111", features = [
1717
magnus = { version = "0.7.1" }
1818
serde = { version = "1.0.219", features = ["derive"] }
1919
serde_magnus = "0.9.0"
20-
codeowners = { git = "https://github.com/rubyatscale/codeowners-rs.git", branch = "ph/cleanup-for-file" }
20+
codeowners = { git = "https://github.com/rubyatscale/codeowners-rs.git", rev = "6646311" }
2121

2222
[dev-dependencies]
2323
rb-sys = { version = "0.9.117", features = [

ext/code_ownership/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ fn for_file(file_path: String) -> Result<Option<Value>, Error> {
3737
}
3838
}
3939

40+
fn version() -> String {
41+
runner::version()
42+
}
43+
4044
fn validate() -> Result<Value, Error> {
4145
let run_config = build_run_config();
4246
let run_result = runner::validate(&run_config, vec![]);
@@ -88,6 +92,7 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
8892
module.define_singleton_method("generate_and_validate", function!(generate_and_validate, 1))?;
8993
module.define_singleton_method("validate", function!(validate, 0))?;
9094
module.define_singleton_method("for_team", function!(for_team, 1))?;
95+
module.define_singleton_method("version", function!(version, 0))?;
9196

9297
Ok(())
9398
}

lib/code_ownership.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ module CodeOwnership
3434
requires_ancestor { Kernel }
3535
GlobsToOwningTeamMap = T.type_alias { T::Hash[String, CodeTeams::Team] }
3636

37+
sig { returns(T::Array[String]) }
38+
def version
39+
["code_ownership version: #{VERSION}",
40+
"codeowners-rs version: #{::RustCodeOwners.version}"]
41+
end
42+
3743
sig { params(file: String).returns(T.nilable(CodeTeams::Team)) }
3844
def for_file(file)
3945
Private::TeamFinder.for_file(file)

lib/code_ownership/cli.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def self.run!(argv)
1616
for_file(argv)
1717
elsif command == 'for_team'
1818
for_team(argv)
19+
elsif command == 'version'
20+
version
1921
elsif [nil, 'help'].include?(command)
2022
puts <<~USAGE
2123
Usage: #{EXECUTABLE} <subcommand>
@@ -72,6 +74,10 @@ def self.validate!(argv)
7274
)
7375
end
7476

77+
def self.version
78+
puts CodeOwnership.version.join("\n")
79+
end
80+
7581
# For now, this just returns team ownership
7682
# Later, this could also return code ownership errors about that file.
7783
def self.for_file(argv)
6.74 MB
Binary file not shown.

sorbet/rbi/manual.rbi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ module RustCodeOwners
1515

1616
def for_team(team)
1717
end
18+
19+
def version
20+
end
1821
end
1922
end

spec/lib/code_ownership/cli_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ def initialize
247247
end
248248
end
249249

250+
describe 'version' do
251+
let(:argv) { ['version'] }
252+
253+
it 'outputs the version' do
254+
expect(CodeOwnership::Cli).to receive(:puts).with(CodeOwnership.version.join("\n"))
255+
subject
256+
end
257+
end
258+
250259
describe 'using unknown command' do
251260
let(:argv) { ['some_command'] }
252261

spec/lib/code_ownership_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,10 @@
212212
end
213213
end
214214
end
215+
216+
describe '.version' do
217+
it 'returns the version' do
218+
expect(described_class.version).to eq ["code_ownership version: #{CodeOwnership::VERSION}", "codeowners-rs version: #{::RustCodeOwners.version}"]
219+
end
220+
end
215221
end

0 commit comments

Comments
 (0)