Module: Ruflet::CLI::ExtraCommand

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

Constant Summary

Constants included from NewCommand

NewCommand::CLIENT_EXTENSION_MAP

Constants included from FlutterSdk

FlutterSdk::DEFAULT_FLUTTER_CHANNEL, FlutterSdk::RELEASES_BASE

Instance Method Summary collapse

Methods included from NewCommand

#command_new

Methods included from FlutterSdk

#ensure_flutter!, #flutter_version_summary

Instance Method Details

#command_create(args) ⇒ Object



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

def command_create(args)
  command_new(args)
end

#command_debug(args) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ruflet/cli/extra_command.rb', line 95

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 let Ruflet manage the client under ./build/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



54
55
56
57
58
# File 'lib/ruflet/cli/extra_command.rb', line 54

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

#command_doctor(args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ruflet/cli/extra_command.rb', line 15

def command_doctor(args)
  verbose = args.delete("--verbose") || args.delete("-v")
  fix = args.delete("--fix")
  client_dir = detect_client_dir
  template_root = resolve_ruflet_client_template_root
  puts "Ruflet doctor"
  puts "  Ruby: #{RUBY_VERSION}"
  puts "  Flutter host target: #{flutter_host || 'unsupported'}"
  if template_root
    puts "  Template: #{template_root}"
  elsif fix
    template_root = ensure_cached_ruflet_client_template!(verbose: !!verbose)
    unless template_root
      warn "  Template: missing"
      warn "Failed to fetch the Ruflet Flutter template from GitHub."
      return 1
    end
    puts "  Template: #{template_root}"
  else
    warn "  Template: missing"
    warn "Run `ruflet doctor --fix` to fetch the Flutter template from GitHub."
  end
  if fix
    tools = ensure_flutter!("doctor", client_dir: client_dir, auto_install: true)
  else
    tools = flutter_tools(client_dir: client_dir, auto_install: false)
    unless tools
      warn "  Flutter: missing"
      warn "Run `ruflet doctor --fix` to install the host-platform Flutter SDK from .fvmrc."
      return 1
    end
  end
  puts "  Flutter: #{flutter_version_summary(tools)}"
  ok = system(tools[:env], tools[:flutter], "doctor", *(verbose ? ["-v"] : []))
  status = $?.exitstatus if $?
  status ||= ok ? 0 : 1
  status
end

#command_emulators(args) ⇒ Object



60
61
62
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
93
# File 'lib/ruflet/cli/extra_command.rb', line 60

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