Skip to content

Commit

Permalink
Merge pull request #220 from noir-cr/features/add-only-formats
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul authored Jan 11, 2024
2 parents 9f2b6f8 + 312ae40 commit d7e9174
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
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

0 comments on commit d7e9174

Please sign in to comment.