Class: WifiWand::Platforms::Mac::Helper::SetupCli

Inherits:
Object
  • Object
show all
Defined in:
lib/wifi_wand/platforms/mac/helper/setup_cli.rb

Defined Under Namespace

Classes: LocationSettingsOpenError

Constant Summary collapse

STEP_LABELS =
{
  install_helper:   'Install wifiwand-helper',
  reinstall_helper: 'Reinstall wifiwand-helper (invalid installation detected)',
  grant_permission: 'Grant location permission in System Settings',
}.freeze
USER_FACING_SETUP_ERROR =

StandardError excludes process-control and VM-level exceptions like Interrupt, SystemExit, and NoMemoryError.

StandardError
USAGE =
'Usage: wifiwand-macos-setup [--reinstall | --remove]'

Instance Method Summary collapse

Constructor Details

#initialize(argv:, setup: nil, out_stream: $stdout, in_stream: $stdin) ⇒ SetupCli

Returns a new instance of SetupCli.

Parameters:

  • argv (Array<String>)

    command-line arguments (e.g. ARGV)

  • setup (Setup) (defaults to: nil)

    injectable for testing; built from out_stream if omitted

  • out_stream (IO) (defaults to: $stdout)

    output sink (default $stdout)

  • in_stream (IO) (defaults to: $stdin)

    input source for the ENTER prompt (default $stdin)



37
38
39
40
41
42
43
# File 'lib/wifi_wand/platforms/mac/helper/setup_cli.rb', line 37

def initialize(argv:, setup: nil, out_stream: $stdout, in_stream: $stdin)
  @argv            = argv.dup
  @out_stream      = out_stream
  @in_stream       = in_stream
  @setup           = setup || Setup.new(out_stream: out_stream)
  @action          = nil
end

Instance Method Details

#runInteger

Run the full setup, reinstall, or remove flow.

Returns:

  • (Integer)

    exit code (0 = success, 1 = failure)



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/wifi_wand/platforms/mac/helper/setup_cli.rb', line 48

def run
  parse_options
  return perform_remove if @action == :remove

  support_status = @setup.helper_support_status
  return perform_not_applicable(support_status) if support_status.unsupported?

  perform_reinstall if @action == :reinstall

  status = @setup.check_status
  return 0 if already_complete?(status)

  print_header
  print_status_table(status)
  steps = status.steps_needed
  print_steps(steps)
  wait_for_enter
  execute_steps(steps)
  0
rescue Interrupt
  @out_stream.puts "\nCancelled."
  1
rescue USER_FACING_SETUP_ERROR => e
  # This is the executable boundary: setup failures should become a clear
  # message and non-zero exit status instead of a Ruby backtrace.
  @out_stream.puts "\n❌ Error: #{e.message}"
  1
end