Module: Ruflet::CLI::ExtraCommand
- Included in:
- Ruflet::CLI
- Defined in:
- lib/ruflet/cli/extra_command.rb
Instance Method Summary collapse
- #command_create(args) ⇒ Object
- #command_debug(args) ⇒ Object
- #command_devices(args) ⇒ Object
- #command_doctor(args) ⇒ Object
- #command_emulators(args) ⇒ Object
- #command_pack(args) ⇒ Object
- #command_publish(args) ⇒ Object
- #command_serve(args) ⇒ Object
Instance Method Details
#command_create(args) ⇒ Object
8 9 10 |
# File 'lib/ruflet/cli/extra_command.rb', line 8 def command_create(args) command_new(args) end |
#command_debug(args) ⇒ Object
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 144 145 146 147 |
# File 'lib/ruflet/cli/extra_command.rb', line 101 def command_debug(args) ensure_flutter!("debug") = { platform: nil, device_id: nil, release: false, verbose: false, web_renderer: nil } parser = OptionParser.new do |o| o.on("--platform NAME") { |v| [:platform] = v } o.on("--device-id ID") { |v| [:device_id] = v } o.on("--release") { [:release] = true } o.on("-v", "--verbose") { [:verbose] = true } o.on("--web-renderer NAME") { |v| [:web_renderer] = v } end parser.parse!(args) [:platform] ||= args.shift cmd = ["flutter", "run"] cmd << "--release" if [:release] cmd << "-v" if [:verbose] cmd += ["--web-renderer", [:web_renderer]] if [:web_renderer] if [:device_id] cmd += ["-d", [:device_id]] else case [:platform] when "web" cmd += ["-d", "chrome"] when "macos", "windows", "linux" cmd += ["-d", [:platform]] when "ios", "android" # let flutter pick the default device end end 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" return 1 end system(*cmd, chdir: client_dir) $?.exitstatus || 1 end |
#command_devices(args) ⇒ Object
25 26 27 28 29 |
# File 'lib/ruflet/cli/extra_command.rb', line 25 def command_devices(args) ensure_flutter!("devices") system("flutter", "devices", *args) $?.exitstatus || 1 end |
#command_doctor(args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ruflet/cli/extra_command.rb', line 12 def command_doctor(args) verbose = args.delete("--verbose") || args.delete("-v") puts "Ruflet doctor" puts " Ruby: #{RUBY_VERSION}" flutter = system("which flutter > /dev/null 2>&1") puts " Flutter: #{flutter ? 'found' : 'missing'}" if flutter system("flutter", "doctor", *(verbose ? ["-v"] : [])) return $?.exitstatus || 0 end 1 end |
#command_emulators(args) ⇒ Object
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 64 |
# File 'lib/ruflet/cli/extra_command.rb', line 31 def command_emulators(args) 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 = ["flutter", "emulators", "--launch", emulator_id] cmd << "-v" if verbose system(*cmd) $?.exitstatus || 1 when "create", "delete" warn "ruflet emulators --#{action} is not implemented yet. Use your platform tools." 1 else cmd = ["flutter", "emulators"] cmd << "-v" if verbose system(*cmd) $?.exitstatus || 1 end end |
#command_pack(args) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/ruflet/cli/extra_command.rb', line 88 def command_pack(args) platform = default_desktop_platform unless platform warn "pack is only supported on desktop hosts (macOS, Windows, Linux)" return 1 end command_build([platform] + args) end |
#command_publish(args) ⇒ Object
97 98 99 |
# File 'lib/ruflet/cli/extra_command.rb', line 97 def command_publish(args) command_build(["web"] + args) end |
#command_serve(args) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ruflet/cli/extra_command.rb', line 66 def command_serve(args) = { port: 8550, root: Dir.pwd } parser = OptionParser.new do |o| o.on("-p", "--port PORT", Integer, "Port (default: 8550)") { |v| [:port] = v } o.on("-r", "--root PATH", "Root directory (default: current dir)") { |v| [:root] = v } end parser.parse!(args) require "webrick" root = File.([:root]) server = WEBrick::HTTPServer.new( Port: [:port], DocumentRoot: root, AccessLog: [], Logger: WEBrick::Log.new($stderr, WEBrick::Log::WARN) ) trap("INT") { server.shutdown } puts "Serving #{root} on http://127.0.0.1:#{[:port]}" server.start 0 end |