Module: NHKore::CLI::FXCmd

Included in:
App
Defined in:
lib/nhkore/cli/fx_cmd.rb

Instance Method Summary collapse

Instance Method Details

#build_fx_cmdObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nhkore/cli/fx_cmd.rb', line 15

def build_fx_cmd
  app = self

  @fx_cmd = @app_cmd.define_command do
    name    'fx'
    usage   'fx [OPTIONS] [COMMAND]...'
    summary 'Test spinner/progress special effects (for running long tasks)'

    description <<-DESC
      Test if the special effects work on your command line:\n
      - #{App::NAME} [-s/-X] fx
    DESC

    flag :a,:all,'test all special effects regardless of global options'

    run do |opts,args,cmd|
      app.refresh_cmd(opts,args,cmd)
      app.run_fx_cmd
    end
  end
end

#run_fx_cmdObject



37
38
39
40
# File 'lib/nhkore/cli/fx_cmd.rb', line 37

def run_fx_cmd
  test_fx_progress_bar
  test_fx_spinner
end

#test_fx_progress_barObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/nhkore/cli/fx_cmd.rb', line 42

def test_fx_progress_bar
  bars = nil

  if @cmd_opts[:all]
    bars = {default: :default,classic: :classic,no: :no}
  else
    bars = {user: @progress_bar}
  end

  bars.each do |name,bar|
    name = name.to_s.capitalize
    bar = build_progress_bar("Testing #{name} progress",download: false,type: bar)

    bar.start

    0.upto(99) do
      sleep(0.05)
      bar.advance
    end

    bar.finish
  end
end

#test_fx_spinnerObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/nhkore/cli/fx_cmd.rb', line 66

def test_fx_spinner
  app_spinner = @spinner
  spinners = nil

  if @cmd_opts[:all]
    spinners = {
      default: App::DEFAULT_SPINNER,
      classic: App::CLASSIC_SPINNER,
      no: {},
    }
  else
    spinners = {
      user: app_spinner
    }
  end

  spinners.each do |name,spinner|
    @spinner = spinner

    start_spin("Testing #{name.to_s.capitalize} spinner")

    1.upto(3) do |i|
      sleep(1.1)
      update_spin_detail(" (#{i}/3)")
    end

    stop_spin
  end

  # Reset back to users'.
  @spinner = app_spinner
end