jrf 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f0245d91775670ab95a99001709aacb8f216f3a5a2ed245a551eeafa7df5e70
4
- data.tar.gz: b535e57a4bb22c37388353282ef7f2bb748251b153abf53e878062b7cc64694b
3
+ metadata.gz: 2776f201f13bf8be05ec4615510f0810ceeff9115dd11ef4d54ed873c9c90030
4
+ data.tar.gz: 0b996f561536a47067d262122c3b1093fd9adfb499fc0fab7011226cee75f043
5
5
  SHA512:
6
- metadata.gz: c9c9f7f3b0739d6037ceafabe8f1e1766b051686ab2c5c3fac51573944326b7356138fb6ae3eb9c719631ebc5947ca451a15cfebb9b4233668cc02cd0f78bda0
7
- data.tar.gz: 2f1e4fd6fc91596adbf5f4221c8a5adf1b443d547b1019032e3961e1424ac9c05826c2db838ab2ed9b09ac4c980291110319ab23938be868850e6afa24d7b277
6
+ metadata.gz: bde0a34fdeb324132084a7621bc2a37767a506261dbafadfdebbeb7fc060a2e8a142c44132ed5228a2604a5dba767871d39303eb3aa941510ba0d3f2694d5e7e
7
+ data.tar.gz: 725b4611d5659ce994df183950676a7c8ff2582df7b02cbc0bf7ef47682ca2bf2f55507df10c6e907a1032c6b4dcd17625b4db807f28d304a331f0caf4c8a1cd
data/Rakefile CHANGED
@@ -8,3 +8,8 @@ Rake::TestTask.new do |t|
8
8
  end
9
9
 
10
10
  task default: :test
11
+
12
+ desc "Build man/jrf.1 from README.md"
13
+ task :man do
14
+ ruby "script/build_man_from_readme.rb"
15
+ end
data/jrf.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["n/a@example.com"]
10
10
 
11
11
  spec.summary = "JSON filter with the power and speed of Ruby"
12
- spec.description = "A JSON filter for NDJSON that uses Ruby expressions for transforms, selection, and aggregation."
12
+ spec.description = "jrf is a JSON filter with the power and speed of Ruby. It lets you write transforms as Ruby expressions, so you can use arbitrary Ruby logic. It supports extraction, filtering, flattening, sorting, and aggregation in stage pipelines."
13
13
  spec.license = "MIT"
14
14
  spec.required_ruby_version = ">= 3.0"
15
15
 
data/lib/jrf/cli.rb CHANGED
@@ -4,23 +4,53 @@ require_relative "runner"
4
4
 
5
5
  module Jrf
6
6
  class CLI
7
+ USAGE = "usage: jrf [-v] [--help] 'STAGE >> STAGE >> ...'"
8
+
9
+ HELP_TEXT = <<~'TEXT'
10
+ usage: jrf [-v] [--help] 'STAGE >> STAGE >> ...'
11
+
12
+ JSON filter with the power and speed of Ruby.
13
+
14
+ Options:
15
+ -v, --verbose print compiled stage Ruby expressions
16
+ -h, --help show this help and exit
17
+
18
+ Pipeline:
19
+ Connect stages with top-level >>.
20
+ The current value in each stage is available as _.
21
+
22
+ Examples:
23
+ jrf '_["foo"]'
24
+ jrf 'select(_["x"] > 10) >> _["foo"]'
25
+ jrf '_["items"] >> flat'
26
+ jrf 'sort(_["at"]) >> _["id"]'
27
+ jrf '_["msg"] >> reduce(nil) { |acc, v| acc ? "#{acc} #{v}" : v }'
28
+
29
+ See Also:
30
+ README.md
31
+ man jrf
32
+ TEXT
33
+
7
34
  def self.run(argv = ARGV, input: ARGF, out: $stdout, err: $stderr)
8
35
  verbose = false
9
36
 
10
37
  while argv.first&.start_with?("-")
11
38
  case argv.first
12
- when "-v"
39
+ when "-v", "--verbose"
13
40
  verbose = true
14
41
  argv.shift
42
+ when "-h", "--help"
43
+ out.puts HELP_TEXT
44
+ return 0
15
45
  else
16
46
  err.puts "unknown option: #{argv.first}"
17
- err.puts "usage: jrf [-v] 'EXPR'"
47
+ err.puts USAGE
18
48
  return 1
19
49
  end
20
50
  end
21
51
 
22
52
  if argv.empty?
23
- err.puts "usage: jrf [-v] 'EXPR'"
53
+ err.puts USAGE
24
54
  return 1
25
55
  end
26
56
 
data/lib/jrf/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jrf
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/test/jrf_test.rb CHANGED
@@ -93,6 +93,23 @@ assert_includes(stderr, "stage[1] kind=extract")
93
93
  assert_includes(stderr, 'original: _["hello"]')
94
94
  assert_includes(stderr, 'ruby: _["hello"]')
95
95
 
96
+ stdout, stderr, status = Open3.capture3("./exe/jrf", "--help")
97
+ assert_success(status, stderr, "help option")
98
+ assert_includes(stdout, "usage: jrf [-v] [--help] 'STAGE >> STAGE >> ...'")
99
+ assert_includes(stdout, "JSON filter with the power and speed of Ruby.")
100
+ assert_includes(stdout, "Pipeline:")
101
+ assert_includes(stdout, "Connect stages with top-level >>.")
102
+ assert_includes(stdout, "The current value in each stage is available as _.")
103
+ assert_includes(stdout, "See Also:")
104
+ assert_includes(stdout, "README.md")
105
+ assert_includes(stdout, "man jrf")
106
+ assert_equal([], lines(stderr), "help stderr output")
107
+
108
+ stdout, stderr, status = run_jrf('select(_["hello"] == 123) >> _["hello"]', input_hello, "--verbose")
109
+ assert_success(status, stderr, "dump stages verbose alias")
110
+ assert_equal(%w[123], lines(stdout), "dump stages verbose alias output")
111
+ assert_includes(stderr, "stage[0] kind=select")
112
+
96
113
  input_regex = <<~NDJSON
97
114
  {"foo":{"bar":"ok"},"x":50}
98
115
  {"foo":{"bar":"ng"},"x":70}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jrf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuho
@@ -9,8 +9,9 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: A JSON filter for NDJSON that uses Ruby expressions for transforms, selection,
13
- and aggregation.
12
+ description: jrf is a JSON filter with the power and speed of Ruby. It lets you write
13
+ transforms as Ruby expressions, so you can use arbitrary Ruby logic. It supports
14
+ extraction, filtering, flattening, sorting, and aggregation in stage pipelines.
14
15
  email:
15
16
  - n/a@example.com
16
17
  executables: