Module: Ruflet::CLI::UpdateCommand

Includes:
RunCommand
Included in:
Ruflet::CLI
Defined in:
lib/ruflet/cli/update_command.rb

Constant Summary collapse

VALID_UPDATE_PLATFORMS =
%w[macos linux windows].freeze

Instance Method Summary collapse

Methods included from RunCommand

#command_run

Instance Method Details

#command_update(args) ⇒ Object



12
13
14
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ruflet/cli/update_command.rb', line 12

def command_update(args)
  options = {
    web: false,
    desktop: false,
    check: false,
    force: false,
    platform: nil
  }

  parser = OptionParser.new do |o|
    o.on("--web") { options[:web] = true }
    o.on("--desktop") { options[:desktop] = true }
    o.on("--check") { options[:check] = true }
    o.on("--force") { options[:force] = true }
    o.on("--platform PLATFORM") { |value| options[:platform] = value.to_s.downcase }
  end
  parser.parse!(args)

  args.each do |arg|
    case arg.to_s.downcase
    when "web"
      options[:web] = true
    when "desktop"
      options[:desktop] = true
    when "all"
      options[:web] = true
      options[:desktop] = true
    when "check"
      options[:check] = true
    else
      warn "Unknown update target: #{arg}"
      return 1
    end
  end

  platform = options[:platform] || host_platform_name
  if platform.nil? || !VALID_UPDATE_PLATFORMS.include?(platform)
    warn "Unsupported or missing platform. Use --platform macos|linux|windows."
    return 1
  end

  if !options[:web] && !options[:desktop]
    options[:web] = true
    options[:desktop] = true
  end

  targets = []
  targets << :web if options[:web]
  targets << :desktop if options[:desktop]

  return check_client_updates(targets, platform: platform) if options[:check]

  targets.each do |target|
    root =
      if target == :web
        ensure_prebuilt_client(web: true, platform: platform, force: options[:force])
      else
        ensure_prebuilt_client(desktop: true, platform: platform, force: options[:force])
      end
    unless root
      warn "Failed to update #{target} client for #{platform}"
      return 1
    end

    manifest = read_client_manifest(root)
    release_label = manifest && manifest["release_tag"] ? manifest["release_tag"] : "unknown release"
    puts "Updated #{target} client for #{platform} at #{root} (#{release_label})"
  end

  0
end