Module: Ruflet::CLI::ExtraCommand

Includes:
FlutterSdk
Included in:
Ruflet::CLI
Defined in:
lib/ruflet/cli/extra_command.rb

Constant Summary

Constants included from FlutterSdk

FlutterSdk::DEFAULT_FLUTTER_CHANNEL, FlutterSdk::RELEASES_BASE

Instance Method Summary collapse

Methods included from FlutterSdk

#ensure_flutter!

Instance Method Details

#command_create(args) ⇒ Object



10
11
12
# File 'lib/ruflet/cli/extra_command.rb', line 10

def command_create(args)
  command_new(args)
end

#command_debug(args) ⇒ Object



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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ruflet/cli/extra_command.rb', line 65

def command_debug(args)
  options = {
    platform: nil,
    device_id: nil,
    release: false,
    verbose: false,
    web_renderer: nil
  }
  parser = OptionParser.new do |o|
    o.on("--platform NAME") { |v| options[:platform] = v }
    o.on("--device-id ID") { |v| options[:device_id] = v }
    o.on("--release") { options[:release] = true }
    o.on("-v", "--verbose") { options[:verbose] = true }
    o.on("--web-renderer NAME") { |v| options[:web_renderer] = v }
  end
  parser.parse!(args)

  options[:platform] ||= args.shift
  client_dir = detect_client_dir
  unless client_dir
    warn "Could not find Flutter client directory."
    warn "Set RUFLET_CLIENT_DIR or place client at ./ruflet_client"
    warn "`ruflet debug` requires Flutter client source code."
    warn "For prebuilt clients, use: `ruflet run --web` or `ruflet run --desktop`."
    return 1
  end

  tools = ensure_flutter!("debug", client_dir: client_dir)
  cmd = [tools[:flutter], "run"]
  cmd << "--release" if options[:release]
  cmd << "-v" if options[:verbose]
  cmd += ["--web-renderer", options[:web_renderer]] if options[:web_renderer]

  if options[:device_id]
    cmd += ["-d", options[:device_id]]
  else
    case options[:platform]
    when "web"
      cmd += ["-d", "chrome"]
    when "macos", "windows", "linux"
      cmd += ["-d", options[:platform]]
    when "ios", "android"
      # let flutter pick the default device
    end
  end

  system(tools[:env], *cmd, chdir: client_dir)
  $?.exitstatus || 1
end

#command_devices(args) ⇒ Object



24
25
26
27
28
# File 'lib/ruflet/cli/extra_command.rb', line 24

def command_devices(args)
  tools = ensure_flutter!("devices")
  system(tools[:env], tools[:flutter], "devices", *args)
  $?.exitstatus || 1
end

#command_doctor(args) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/ruflet/cli/extra_command.rb', line 14

def command_doctor(args)
  verbose = args.delete("--verbose") || args.delete("-v")
  puts "Ruflet doctor"
  puts "  Ruby: #{RUBY_VERSION}"
  tools = ensure_flutter!("doctor")
  puts "  Flutter: #{tools[:flutter]}"
  system(tools[:env], tools[:flutter], "doctor", *(verbose ? ["-v"] : []))
  $?.exitstatus || 1
end

#command_emulators(args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ruflet/cli/extra_command.rb', line 30

def command_emulators(args)
  tools = ensure_flutter!("emulators")
  action = nil
  emulator_id = nil
  verbose = false
  parser = OptionParser.new do |o|
    o.on("--create") { action = "create" }
    o.on("--delete") { action = "delete" }
    o.on("--start") { action = "start" }
    o.on("--emulator ID") { |v| emulator_id = v }
    o.on("-v", "--verbose") { verbose = true }
  end
  parser.parse!(args)

  case action
  when "start"
    unless emulator_id
      warn "Missing --emulator for start"
      return 1
    end
    cmd = [tools[:flutter], "emulators", "--launch", emulator_id]
    cmd << "-v" if verbose
    system(tools[:env], *cmd)
    $?.exitstatus || 1
  when "create", "delete"
    warn "ruflet emulators --#{action} is not implemented yet. Use your platform tools."
    1
  else
    cmd = [tools[:flutter], "emulators"]
    cmd << "-v" if verbose
    system(tools[:env], *cmd)
    $?.exitstatus || 1
  end
end