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



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

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



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

def run_fx_cmd
  test_fx_progress_bar
  test_fx_spinner
end

#test_fx_progress_barObject



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

def test_fx_progress_bar
  bars = if @cmd_opts[:all]
           {default: :default,classic: :classic,no: :no}
         else
           {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



63
64
65
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
# File 'lib/nhkore/cli/fx_cmd.rb', line 63

def test_fx_spinner
  app_spinner = @spinner
  spinners = if @cmd_opts[:all]
               {
                 default: App::DEFAULT_SPINNER,
                 classic: App::CLASSIC_SPINNER,
                 no: {},
               }
             else
               {
                 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