Class: Harnex::History

Inherits:
Object
  • Object
show all
Defined in:
lib/harnex/commands/history.rb

Constant Summary collapse

DEFAULT_LIMIT =
5

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ History

Returns a new instance of History.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/harnex/commands/history.rb', line 24

def initialize(argv)
  @argv = argv.dup
  @options = {
    limit: DEFAULT_LIMIT,
    since: nil,
    id: nil,
    global: false,
    json: false,
    all: false,
    help: false
  }
end

Class Method Details

.usage(program_name = "harnex history") ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/harnex/commands/history.rb', line 9

def self.usage(program_name = "harnex history")
  <<~TEXT
    Usage: #{program_name} [options]

    Options:
      --limit N   Number of records to show (default: #{DEFAULT_LIMIT})
      --since DUR Only show records started within DUR (examples: 1h, 1d)
      --id TEXT   Filter records whose id contains TEXT
      --global    Read the global no-repo history file
      --json      Output JSONL instead of a table
      --all       Show all matching records
      -h, --help  Show this help
  TEXT
end

Instance Method Details

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/harnex/commands/history.rb', line 37

def run
  parser.parse!(@argv)
  if @options[:help]
    puts self.class.usage
    return 0
  end

  records = filtered_records
  if @options[:json]
    records.each { |record| puts JSON.generate(record) }
  elsif !records.empty?
    puts render_table(records)
  end
  0
end