Class: Autoproj::CLI::Main

Inherits:
Thor
  • Object
show all
Defined in:
lib/autoproj/cli/main.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.default_report_on_package_failuresObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Override the CLI logic to determine what should be done on package failure (between raising or exiting)

This is used mainly in tests, to make sure that the CLI won’t be calling exit(). Set to nil to restore the default behavior



51
52
53
# File 'lib/autoproj/cli/main.rb', line 51

def default_report_on_package_failures
  @default_report_on_package_failures
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/autoproj/cli/main.rb', line 39

def self.exit_on_failure?
    true
end

.register_post_command_hook(: update) {|ws, params| ... } ⇒ Object .register_post_command_hook(: build) {|ws, params| ... } ⇒ Object

Register a hook that should be called at a given event

Overloads:

  • .register_post_command_hook(: update) {|ws, params| ... } ⇒ Object

    Hook called after an update operation (from the CLI, either update or osdeps)

    The params contain :source_packages and :osdeps_packages, respectively the list of names of the source and osdeps packages selected for the update operation (NOT the list of packages actually updated)

    Yield Parameters:

  • .register_post_command_hook(: build) {|ws, params| ... } ⇒ Object

    Hook called after a build operation (from the CLI, build)

    The params contain :source_packages, the list of names of the source and osdeps packages selected for the update operation (NOT the list of packages actually updated)

    Yield Parameters:



86
87
88
# File 'lib/autoproj/cli/main.rb', line 86

def self.register_post_command_hook(hook_name, &block)
    @post_command_hooks[hook_name.to_sym] << block
end

.run_post_command_hook(hook_name, ws, **args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run hooks defined for a given hook name



57
58
59
60
61
# File 'lib/autoproj/cli/main.rb', line 57

def self.run_post_command_hook(hook_name, ws, **args)
    @post_command_hooks[hook_name].each do |hook|
        hook.call(ws, args)
    end
end

Instance Method Details

#bootstrap(*args) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/autoproj/cli/main.rb', line 154

def bootstrap(*args)
    unless File.directory?(File.join(Dir.pwd, ".autoproj"))
        require "autoproj/ops/install"
        ops = Autoproj::Ops::Install.new(Dir.pwd)
        bootstrap_options = ops.parse_options(thor_options_to_optparse + args)
        ops.run
        exec Gem.ruby, $0, "bootstrap", *bootstrap_options
    end
    run_autoproj_cli(:bootstrap, :Bootstrap, Hash[], *args)
end

#build(*packages) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/autoproj/cli/main.rb', line 276

def build(*packages)
    report_options = Hash[silent: false, on_package_failures: default_report_on_package_failures]
    report_options[:on_package_failures] = :report if options[:auto_exclude]

    failures = run_autoproj_cli(:build, :Build, report_options, *packages,
                                tool_failure_mode: :report_silent)
    unless failures.empty?
        Autobuild.silent = false
        package_failures, config_failures = failures.partition do |e|
            e.respond_to?(:target) && e.target.respond_to?(:name)
        end

        packages_failed = package_failures
                          .map do |e|
            if e.respond_to?(:target) && e.target.respond_to?(:name)
                e.target.name
            end
        end.compact
        unless packages_failed.empty?
            Autobuild.error "#{packages_failed.size} packages failed: #{packages_failed.sort.join(', ')}"
        end
        config_failures.each do |e|
            Autobuild.error(e)
        end
        exit 1
    end
end

#cache(*args) ⇒ Object



332
333
334
# File 'lib/autoproj/cli/main.rb', line 332

def cache(*args)
    run_autoproj_cli(:cache, :Cache, Hash[], *args)
end

#clean(*packages) ⇒ Object



354
355
356
# File 'lib/autoproj/cli/main.rb', line 354

def clean(*packages)
    run_autoproj_cli(:clean, :Clean, Hash[], *packages)
end

#commit(*packages) ⇒ Object



499
500
501
# File 'lib/autoproj/cli/main.rb', line 499

def commit(*packages)
    run_autoproj_cli(:commit, :Commit, Hash[], *packages, deps: true)
end

#envshObject



166
167
168
# File 'lib/autoproj/cli/main.rb', line 166

def envsh
    run_autoproj_cli(:envsh, :Envsh, Hash[])
end

#exec(*args) ⇒ Object



604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/autoproj/cli/main.rb', line 604

def exec(*args)
    require "autoproj/cli/exec"
    Autoproj.report(
        on_package_failures: default_report_on_package_failures,
        debug: options[:debug],
        silent: true
    ) do
        opts = {}
        use_cache = options[:use_cache]
        opts[:interactive] = options[:interactive]
        opts[:chdir] = options[:chdir]
        opts[:package] = options[:package]
        opts[:use_cached_env] = use_cache unless use_cache.nil?
        CLI::Exec.new.run(*args, **opts)
    end
end

#install_stage2(root_dir, *vars) ⇒ Object



561
562
563
564
565
566
# File 'lib/autoproj/cli/main.rb', line 561

def install_stage2(root_dir, *vars)
    require "autoproj/ops/install"
    ops = Autoproj::Ops::Install.new(root_dir)
    ops.parse_options(thor_options_to_optparse)
    ops.stage2(*vars)
end

#locate(*packages) ⇒ Object



367
368
369
# File 'lib/autoproj/cli/main.rb', line 367

def locate(*packages)
    run_autoproj_cli(:locate, :Locate, Hash[], *packages)
end

#log(*args) ⇒ Object



447
448
449
# File 'lib/autoproj/cli/main.rb', line 447

def log(*args)
    run_autoproj_cli(:log, :Log, Hash[], *args)
end

#manifest(*name) ⇒ Object



587
588
589
# File 'lib/autoproj/cli/main.rb', line 587

def manifest(*name)
    run_autoproj_cli(:manifest, :Manifest, Hash[silent: true], *name)
end

#osdeps(*packages) ⇒ Object



402
403
404
# File 'lib/autoproj/cli/main.rb', line 402

def osdeps(*packages)
    run_autoproj_cli(:osdeps, :OSDeps, Hash[silent: options[:system_info]], *packages)
end

#patch(*packages) ⇒ Object



576
577
578
# File 'lib/autoproj/cli/main.rb', line 576

def patch(*packages)
    run_autoproj_cli(:patcher, :Patcher, Hash[], *packages, patch: true)
end

#query(query_string = nil) ⇒ Object



555
556
557
# File 'lib/autoproj/cli/main.rb', line 555

def query(query_string = nil)
    run_autoproj_cli(:query, :Query, Hash[], *Array(query_string))
end

#reconfigureObject



374
375
376
# File 'lib/autoproj/cli/main.rb', line 374

def reconfigure
    run_autoproj_cli(:reconfigure, :Reconfigure, Hash[])
end

#reset(version_id) ⇒ Object



460
461
462
# File 'lib/autoproj/cli/main.rb', line 460

def reset(version_id)
    run_autoproj_cli(:reset, :Reset, Hash[], version_id)
end

#show(*packages) ⇒ Object



393
394
395
# File 'lib/autoproj/cli/main.rb', line 393

def show(*packages)
    run_autoproj_cli(:show, :Show, Hash[], *packages)
end

#status(*packages) ⇒ Object



190
191
192
# File 'lib/autoproj/cli/main.rb', line 190

def status(*packages)
    run_autoproj_cli(:status, :Status, Hash[], *packages)
end

#switch_config(*args) ⇒ Object



523
524
525
# File 'lib/autoproj/cli/main.rb', line 523

def switch_config(*args)
    run_autoproj_cli(:switch_config, :SwitchConfig, Hash[], *args)
end

#tag(tag_name = nil, *packages) ⇒ Object



478
479
480
# File 'lib/autoproj/cli/main.rb', line 478

def tag(tag_name = nil, *packages)
    run_autoproj_cli(:tag, :Tag, Hash[], tag_name, *packages)
end

#unpatch(*packages) ⇒ Object



582
583
584
# File 'lib/autoproj/cli/main.rb', line 582

def unpatch(*packages)
    run_autoproj_cli(:patcher, :Patcher, Hash[], *packages, patch: false)
end

#update(*packages) ⇒ Object



236
237
238
239
240
241
# File 'lib/autoproj/cli/main.rb', line 236

def update(*packages)
    report_options = Hash[silent: false, on_package_failures: default_report_on_package_failures]
    report_options[:on_package_failures] = :report if options[:auto_exclude]

    run_autoproj_cli(:update, :Update, report_options, *packages, run_hook: true)
end

#version(*args) ⇒ Object



409
410
411
# File 'lib/autoproj/cli/main.rb', line 409

def version(*args)
    run_autoproj_cli(:version, :Version, Hash[], *args)
end

#versions(*packages) ⇒ Object



437
438
439
# File 'lib/autoproj/cli/main.rb', line 437

def versions(*packages)
    run_autoproj_cli(:versions, :Versions, Hash[], *packages, deps: true)
end

#watchObject



173
174
175
# File 'lib/autoproj/cli/main.rb', line 173

def watch
    run_autoproj_cli(:watch, :Watch, Hash[])
end

#which(cmd) ⇒ Object



626
627
628
629
630
631
632
633
634
# File 'lib/autoproj/cli/main.rb', line 626

def which(cmd)
    require "autoproj/cli/which"
    Autoproj.report(on_package_failures: default_report_on_package_failures, debug: options[:debug], silent: true) do
        opts = Hash.new
        use_cache = options[:use_cache]
        opts[:use_cached_env] = use_cache unless use_cache.nil?
        CLI::Which.new.run(cmd, **opts)
    end
end