Class: Serialbench::Cli::EnvironmentCli

Inherits:
BaseCli
  • Object
show all
Defined in:
lib/serialbench/cli/environment_cli.rb

Overview

Environment management CLI

Instance Method Summary collapse

Methods inherited from BaseCli

exit_on_failure?

Instance Method Details

#execute(environment_path, benchmark_config_path, result_dir) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/serialbench/cli/environment_cli.rb', line 99

def execute(environment_path, benchmark_config_path, result_dir)
  benchmark_config = load_benchmark_config(benchmark_config_path)
  environment_config = load_environment_config(environment_path)

  say "🚀 Running benchmark '#{benchmark_config_path}' in environment '#{environment_config.name}'...", :green

  FileUtils.mkdir_p(result_dir)
  say "Results will be saved to: #{result_dir}", :cyan

  runner = Runners.for(environment_config, environment_path)
  runner.run_benchmark(benchmark_config, benchmark_config_path, result_dir)

  say '✅ Benchmark completed successfully!', :green
  say "Results saved to: #{result_dir}", :cyan
rescue StandardError => e
  say "❌ Benchmark failed: #{e.message}", :red
  exit 1
end

#new(name, kind, ruby_build_tag) ⇒ Object



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
83
84
85
# File 'lib/serialbench/cli/environment_cli.rb', line 32

def new(name, kind, ruby_build_tag)
  validate_name(name)

  config_path = File.join(options[:dir], "#{name}.yml")

  if File.exist?(config_path)
    say "Environment '#{name}' already exists at #{config_path}", :yellow
    return unless yes?('Overwrite existing environment? (y/n)')
  end

  FileUtils.mkdir_p(options[:dir])

  kind_config = case kind
                when 'docker'
                  raise ArgumentError, '--docker_image and --dockerfile are required for docker environments' unless options[:docker_image] && options[:dockerfile]

                  Models::EnvironmentConfig.new(
                    name: name,
                    kind: kind,
                    ruby_build_tag: ruby_build_tag,
                    docker: Models::DockerEnvConfig.new(
                      image: options[:docker_image],
                      dockerfile: options[:dockerfile]
                    ),
                    description: "Docker environment for Ruby #{ruby_build_tag} benchmarks"
                  )
                when 'asdf'
                  Models::EnvironmentConfig.new(
                    name: name,
                    kind: kind,
                    ruby_build_tag: ruby_build_tag,
                    asdf: Models::AsdfEnvConfig.new(auto_install: true),
                    description: "ASDF environment for Ruby #{ruby_build_tag} benchmarks"
                  )
                when 'local'
                  Models::EnvironmentConfig.new(
                    name: name,
                    kind: kind,
                    ruby_build_tag: ruby_build_tag,
                    description: "Local environment for Ruby #{ruby_build_tag} benchmarks"
                  )
                else
                  raise ArgumentError, "unknown environment kind: #{kind} (expected local, docker, or asdf)"
                end
  File.write(config_path, kind_config.to_yaml)

  say "✅ Created environment template: #{config_path}", :green

  say ''
  say 'Next steps:', :white
  say "1. Edit #{config_path} to confirm/change configuration", :cyan
  say "2. Validate: serialbench environment validate #{config_path}", :cyan
  say "3. Run benchmark: serialbench benchmark execute #{config_path} config/short.yml", :cyan
end

#prepare(environment_config_path) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/serialbench/cli/environment_cli.rb', line 129

def prepare(environment_config_path)
  environment_config = load_environment_config(environment_config_path)

  say "🔧 Preparing environment '#{environment_config.name}'...", :green

  runner = Runners.for(environment_config, environment_config_path)
  runner.prepare

  say '✅ Environment prepared successfully!', :green
rescue StandardError => e
  say "❌ Environment preparation failed: #{e.message}", :red
  say e.backtrace.join("\n"), :red
  exit 1
end