Skip to content

Commit 2fc2900

Browse files
committed
extracting ForFileOutputBuilder for clarity
1 parent 5218224 commit 2fc2900

File tree

1 file changed

+1
-48
lines changed

1 file changed

+1
-48
lines changed

lib/code_ownership/cli.rb

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -111,54 +111,7 @@ def self.for_file(argv)
111111
raise "Please pass in one file. Use `#{EXECUTABLE} for_file --help` for more info"
112112
end
113113

114-
if options[:verbose]
115-
for_file_verbose(file: files.first, json: options[:json])
116-
else
117-
for_file_terse(file: files.first, json: options[:json])
118-
end
119-
end
120-
121-
def self.for_file_terse(file:, json:)
122-
team = CodeOwnership.for_file(file)
123-
124-
team_name = team&.name || 'Unowned'
125-
team_yml = team&.config_yml || 'Unowned'
126-
127-
if json
128-
json_output = {
129-
team_name: team_name,
130-
team_yml: team_yml
131-
}
132-
133-
puts json_output.to_json
134-
else
135-
puts <<~MSG
136-
Team: #{team_name}
137-
Team YML: #{team_yml}
138-
MSG
139-
end
140-
end
141-
142-
def self.for_file_verbose(file:, json:)
143-
verbose = CodeOwnership.for_file_verbose(file) || {team_name: 'Unowned', team_config_yml: 'Unowned', reasons: []}
144-
145-
if json
146-
json = {
147-
team_name: verbose[:team_name],
148-
team_yml: verbose[:team_config_yml],
149-
reasons: verbose[:reasons]
150-
}
151-
152-
puts json.to_json
153-
else
154-
messages = ["Team: #{verbose[:team_name]}", "Team YML: #{verbose[:team_config_yml]}"]
155-
if verbose[:reasons].any?
156-
messages << "Reasons:\n- #{verbose[:reasons].join("\n-")}"
157-
end
158-
messages.last << "\n"
159-
160-
puts messages.join("\n")
161-
end
114+
puts CodeOwnership::Private::ForFileOutputBuilder.build(file_path: files.first, json: !!options[:json], verbose: !!options[:verbose])
162115
end
163116

164117
def self.for_team(argv)

0 commit comments

Comments
 (0)