hiiro 0.1.361 → 0.1.362

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: e1a1f6f0db99f2573bda6b2c6e8746e49464a4079d40534b6367aa5c888d4557
4
- data.tar.gz: f805de24c6a10db384b4bbb5141edc8d9f0511d9b07cf8c81c4ada064cb6d50e
3
+ metadata.gz: a175bf67aa12a51e5cfefdcd556c47466f47d86e633fdb015eab163225db1c21
4
+ data.tar.gz: adda6458c9cde507d21f49d133171d7d96a2dbb03360d518adaad7e6d74eacf7
5
5
  SHA512:
6
- metadata.gz: 5008e27fbd04a84a473fd12f81d41d758a8e147d2455abb69d33417741feabf5d2605a7697e3b462f56b121b627c46d9bbaeb067663be39a605e70a4ae9592e9
7
- data.tar.gz: 15ac3b8449da827b76e5bbf68fac2e40dfe468526cef493e14d9887e32ad1a0a5f04830f260b82ee9adfc55d7df67d6272c54cbb11406c0a2881bc751ce04df4
6
+ metadata.gz: 6db9a4fbf07b07006a1c4ce5a4b03f8dd8f918e64a7fd2055f45c581eae06107552189e5598e1fdc38ed42e40b5bd8962e03c723aaecd41ddc0ef820578a93e2
7
+ data.tar.gz: 23d2ecee15514029997c3447ce1796a2692e3362dbe52161d3f128bc04d7931623c71dc410cf5e9d7d7ccc1aa706a4cda0c5064814368f107ca1d31e4b9fc859
data/bin/h-date ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hiiro'
4
+ require 'time'
5
+
6
+ # Parse a timestamp string as unix seconds (10-digit) or milliseconds (13-digit)
7
+ def parse_unix(str, ms: nil)
8
+ n = Rational(str.to_s)
9
+ ms = str.to_s.sub(/\..*/, '').length > 11 if ms.nil?
10
+ Time.at(ms ? n / 1000 : n)
11
+ end
12
+
13
+ def parse_date(str)
14
+ str.nil? || str.empty? || str == 'now' ? Time.now : Time.parse(str)
15
+ end
16
+
17
+ Hiiro.run(*ARGV) do
18
+ add_flag(:ms, short: :m, desc: 'Use milliseconds instead of seconds')
19
+ add_flag(:utc, short: :u, desc: 'Output in UTC')
20
+
21
+ # h date to_unix [date-string] -> unix seconds (or ms with --ms)
22
+ add_cmd(:to_unix, :unix, :ts, opts: %i[ms]) do
23
+ t = parse_date(@opts.args.join(' '))
24
+ puts @opts.ms ? (t.to_f * 1000).round : t.to_i
25
+ end
26
+
27
+ # h date from_unix <timestamp> -> human date (auto-detects ms by digit count)
28
+ add_cmd(:from_unix, :parse, opts: %i[ms utc]) do
29
+ raw = @opts.args.first or abort 'usage: h date from_unix <timestamp> [--ms] [--utc]'
30
+ t = parse_unix(raw, ms: @opts.ms ? true : nil)
31
+ t = t.utc if @opts.utc
32
+ puts t.iso8601(3)
33
+ end
34
+
35
+ # h date fmt Y-m-d H:M:S -> strftime with % auto-inserted before each char
36
+ add_cmd(:fmt, :format, :strftime, opts: %i[utc]) do
37
+ fmt = @opts.args.join(' ')
38
+ abort 'usage: h date fmt <strftime-chars-without-percent>' if fmt.empty?
39
+ with_percent = fmt.gsub(/[A-Za-z%]/) { |c| c == '%' ? '%%' : "%#{c}" }
40
+ t = @opts.utc ? Time.now.utc : Time.now
41
+ puts t.strftime(with_percent)
42
+ end
43
+
44
+ add_cmd(:now, opts: %i[utc]) do
45
+ t = @opts.utc ? Time.now.utc : Time.now
46
+ puts t.iso8601
47
+ end
48
+ end
data/bin/h-time ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hiiro'
4
+ require 'time'
5
+
6
+ # Parse a timestamp string as unix seconds (10-digit) or milliseconds (13-digit)
7
+ def parse_unix(str, ms: nil)
8
+ n = Rational(str.to_s)
9
+ ms = str.to_s.sub(/\..*/, '').length > 11 if ms.nil?
10
+ Time.at(ms ? n / 1000 : n)
11
+ end
12
+
13
+ def parse_time(str)
14
+ str.nil? || str.empty? || str == 'now' ? Time.now : Time.parse(str)
15
+ end
16
+
17
+ Hiiro.run(*ARGV) do
18
+ add_flag(:ms, short: :m, desc: 'Use milliseconds instead of seconds')
19
+ add_flag(:utc, short: :u, desc: 'Output in UTC')
20
+
21
+ # h time to_unix [time-string] -> unix seconds (or ms with --ms)
22
+ add_cmd(:to_unix, :unix, :ts, opts: %i[ms]) do
23
+ t = parse_time(@opts.args.join(' '))
24
+ puts @opts.ms ? (t.to_f * 1000).round : t.to_i
25
+ end
26
+
27
+ # h time from_unix <timestamp> -> HH:MM:SS.mmm (auto-detects ms by digit count)
28
+ add_cmd(:from_unix, :parse, opts: %i[ms utc]) do
29
+ raw = @opts.args.first or abort 'usage: h time from_unix <timestamp> [--ms] [--utc]'
30
+ t = parse_unix(raw, ms: @opts.ms ? true : nil)
31
+ t = t.utc if @opts.utc
32
+ puts t.strftime('%H:%M:%S.%L')
33
+ end
34
+
35
+ # h time fmt H:M:S -> strftime with % auto-inserted before each char
36
+ add_cmd(:fmt, :format, :strftime, opts: %i[utc]) do
37
+ fmt = @opts.args.join(' ')
38
+ abort 'usage: h time fmt <strftime-chars-without-percent>' if fmt.empty?
39
+ with_percent = fmt.gsub(/[A-Za-z%]/) { |c| c == '%' ? '%%' : "%#{c}" }
40
+ t = @opts.utc ? Time.now.utc : Time.now
41
+ puts t.strftime(with_percent)
42
+ end
43
+
44
+ add_cmd(:now, opts: %i[ms utc]) do
45
+ t = @opts.utc ? Time.now.utc : Time.now
46
+ puts t.strftime(@opts.ms ? '%H:%M:%S.%L' : '%H:%M:%S')
47
+ end
48
+ end
data/lib/hiiro/options.rb CHANGED
@@ -89,7 +89,11 @@ class Hiiro
89
89
  subset = self.class.setup {}
90
90
  names.each do |name|
91
91
  defn = @definitions[name.to_sym]
92
- subset.definitions[name.to_sym] = defn if defn
92
+ if defn
93
+ subset.definitions[name.to_sym] = defn
94
+ else
95
+ subset.definitions[name.to_sym] = Definition.new(name, short: name.to_s.chars.first, desc: "auto-created flag: #{name}")
96
+ end
93
97
  end
94
98
  subset
95
99
  end
data/lib/hiiro/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  class Hiiro
2
- VERSION = "0.1.361"
2
+ VERSION = "0.1.362"
3
3
  SUPPORTED_RUBY_VERSION = ">= 3.2.0"
4
4
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiiro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.361
4
+ version: 0.1.362
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-09-12 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: pry
@@ -150,6 +151,7 @@ files:
150
151
  - bin/h-commit
151
152
  - bin/h-config
152
153
  - bin/h-cpr
154
+ - bin/h-date
153
155
  - bin/h-db
154
156
  - bin/h-img
155
157
  - bin/h-link
@@ -168,6 +170,7 @@ files:
168
170
  - bin/h-sha
169
171
  - bin/h-sparse
170
172
  - bin/h-tags
173
+ - bin/h-time
171
174
  - bin/h-title
172
175
  - bin/h-todo
173
176
  - bin/h-window
@@ -409,6 +412,7 @@ metadata:
409
412
  homepage_uri: https://github.com/unixsuperhero/hiiro
410
413
  source_code_uri: https://github.com/unixsuperhero/hiiro
411
414
  changelog_uri: https://github.com/unixsuperhero/hiiro/blob/main/CHANGELOG.md
415
+ post_install_message:
412
416
  rdoc_options: []
413
417
  require_paths:
414
418
  - lib
@@ -423,7 +427,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
423
427
  - !ruby/object:Gem::Version
424
428
  version: '0'
425
429
  requirements: []
426
- rubygems_version: 4.0.3
430
+ rubygems_version: 3.5.22
431
+ signing_key:
427
432
  specification_version: 4
428
433
  summary: A lightweight CLI framework for Ruby
429
434
  test_files: []