Skip to content

Commit

Permalink
Merge pull request #222 from noir-cr/add-jsonl-format
Browse files Browse the repository at this point in the history
Add output format (jsonl / #217)
  • Loading branch information
hahwul authored Jan 12, 2024
2 parents b6303da + 6849981 commit e63c9bc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,22 @@ Usage: noir <flags>
Output:
-f FORMAT, --format json Set output format
[plain/json/yaml/markdown-table/curl/httpie/oas2/oas3]
* plain yaml json jsonl markdown-table
* curl httpie oas2 oas3
* only-url only-param only-header only-cookie
-o PATH, --output out.txt Write result to file
--set-pvalue VALUE Specifies the value of the identified parameter
--include-path Include file path in the plain result
--no-color Disable color output
--no-log Displaying only the results
Deliver:
--send-req Send the results to the web request
--send-proxy http://proxy.. Send the results to the web request via http proxy
--send-es http://es.. Send the results to elasticsearch
--with-headers X-Header:Value Add Custom Headers to be Used in Deliver
--use-matchers string Delivers URLs that match a specific condition
--use-filters string Excludes URLs that match a specific condition
--send-req Send results to a web request
--send-proxy http://proxy.. Send results to a web request via an HTTP proxy
--send-es http://es.. Send results to Elasticsearch
--with-headers X-Header:Value Add custom headers to be included in the delivery
--use-matchers string Send URLs that match specific conditions to the Deliver
--use-filters string Exclude URLs that match specified conditions and send the rest to Deliver
Technologies:
-t TECHS, --techs rails,php Specify the technologies to use
Expand Down
5 changes: 5 additions & 0 deletions spec/unit_test/models/output_builder_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ describe "Initialize" do
object = OutputBuilderOnlyCookie.new options
object.output_file.should eq("output.json")
end

it "OutputBuilderJsonl" do
object = OutputBuilderJsonl.new options
object.output_file.should eq("output.json")
end
end
7 changes: 5 additions & 2 deletions src/models/noir.cr
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,13 @@ class NoirRunner

def report
case options[:format]
when "json"
puts @endpoints.to_json
when "yaml"
puts @endpoints.to_yaml
when "json"
puts @endpoints.to_json
when "jsonl"
builder = OutputBuilderJsonl.new @options
builder.print @endpoints
when "markdown-table"
builder = OutputBuilderMarkdownTable.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 oas2 oas3\n * only-url only-param only-header only-cookie" { |var| noir_options[:format] = var }
parser.on "-f FORMAT", "--format json", "Set output format\n * plain yaml json jsonl 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
10 changes: 10 additions & 0 deletions src/output_builder/jsonl.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "../models/output_builder"
require "../models/endpoint"

class OutputBuilderJsonl < OutputBuilder
def print(endpoints : Array(Endpoint))
endpoints.each do |endpoint|
ob_puts endpoint.to_json
end
end
end

0 comments on commit e63c9bc

Please sign in to comment.