Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add only-* formats (#217) #220

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions spec/unit_test/models/output_builder_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ describe "Initialize" do
object = OutputBuilderOnlyUrl.new options
object.output_file.should eq("output.json")
end

it "OutputBuilderOnlyParam" do
object = OutputBuilderOnlyParam.new options
object.output_file.should eq("output.json")
end

it "OutputBuilderOnlyHeader" do
object = OutputBuilderOnlyHeader.new options
object.output_file.should eq("output.json")
end

it "OutputBuilderOnlyCookie" do
object = OutputBuilderOnlyCookie.new options
object.output_file.should eq("output.json")
end
end
9 changes: 9 additions & 0 deletions src/models/noir.cr
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ class NoirRunner
when "only-url"
builder = OutputBuilderOnlyUrl.new @options
builder.print @endpoints
when "only-param"
builder = OutputBuilderOnlyParam.new @options
builder.print @endpoints
when "only-header"
builder = OutputBuilderOnlyHeader.new @options
builder.print @endpoints
when "only-cookie"
builder = OutputBuilderOnlyCookie.new @options
builder.print @endpoints
else
builder = OutputBuilderCommon.new @options
builder.print @endpoints
Expand Down
2 changes: 1 addition & 1 deletion src/noir.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ OptionParser.parse do |parser|

parser.separator "\n Output:".colorize(:blue)

parser.on "-f FORMAT", "--format json", "Set output format\n * plain json yaml markdown-table\n * curl httpie only-url\n * oas2 oas3" { |var| noir_options[:format] = var }
parser.on "-f FORMAT", "--format json", "Set output format\n * plain json yaml markdown-table\n * curl httpie oas2 oas3\n * only-url only-param only-header only-cookie" { |var| noir_options[:format] = var }
parser.on "-o PATH", "--output out.txt", "Write result to file" { |var| noir_options[:output] = var }
parser.on "--set-pvalue VALUE", "Specifies the value of the identified parameter" { |var| noir_options[:set_pvalue] = var }
parser.on "--include-path", "Include file path in the plain result" do
Expand Down
19 changes: 19 additions & 0 deletions src/output_builder/only-cookie.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "../models/output_builder"
require "../models/endpoint"

class OutputBuilderOnlyCookie < OutputBuilder
def print(endpoints : Array(Endpoint))
cookies = [] of String
endpoints.each do |endpoint|
endpoint.params.each do |param|
if param.param_type == "cookie"
cookies << param.name
end
end
end

cookies.uniq.each do |cookie|
puts cookie.colorize(:light_green).toggle(@is_color)
end
end
end
19 changes: 19 additions & 0 deletions src/output_builder/only-header.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "../models/output_builder"
require "../models/endpoint"

class OutputBuilderOnlyHeader < OutputBuilder
def print(endpoints : Array(Endpoint))
headers = [] of String
endpoints.each do |endpoint|
endpoint.params.each do |param|
if param.param_type == "header"
headers << param.name
end
end
end

headers.uniq.each do |header|
puts header.colorize(:light_green).toggle(@is_color)
end
end
end
21 changes: 21 additions & 0 deletions src/output_builder/only-param.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "../models/output_builder"
require "../models/endpoint"

class OutputBuilderOnlyParam < OutputBuilder
def print(endpoints : Array(Endpoint))
common_params = [] of String
targets = ["query", "json", "form"]

endpoints.each do |endpoint|
endpoint.params.each do |param|
if targets.includes? param.param_type
common_params << param.name
end
end
end

common_params.uniq.each do |common_param|
puts common_param.colorize(:light_green).toggle(@is_color)
end
end
end