class Autoproj::CLI::Main

Attributes

default_report_on_package_failures[RW]

@api private

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

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/autoproj/cli/main.rb, line 39
def self.exit_on_failure?
    true
end
register_post_command_hook(hook_name, &block) click to toggle source

Register a hook that should be called at a given event

@overload register_post_command_hook(:update)

@yieldparam [Workspace] ws
@yieldparam [Hash] params

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)

@overload register_post_command_hook(:build)

@yieldparam [Workspace] ws
@yieldparam [Hash] params

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)
# 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) click to toggle source

@api private

Run hooks defined for a given hook name

# 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

Public Instance Methods

bootstrap(*args) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/autoproj/cli/main.rb, line 332
def cache(*args)
    run_autoproj_cli(:cache, :Cache, Hash[], *args)
end
clean(*packages) click to toggle source
# File lib/autoproj/cli/main.rb, line 354
def clean(*packages)
    run_autoproj_cli(:clean, :Clean, Hash[], *packages)
end
commit(*packages) click to toggle source
# File lib/autoproj/cli/main.rb, line 499
def commit(*packages)
    run_autoproj_cli(:commit, :Commit, Hash[], *packages, deps: true)
end
default_report_on_package_failures() click to toggle source
# File lib/autoproj/cli/main.rb, line 93
def default_report_on_package_failures
    if (override = Main.default_report_on_package_failures)
        override
    elsif options[:debug]
        :raise
    else
        :exit
    end
end
envsh() click to toggle source
# File lib/autoproj/cli/main.rb, line 166
def envsh
    run_autoproj_cli(:envsh, :Envsh, Hash[])
end
exec(*args) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/autoproj/cli/main.rb, line 367
def locate(*packages)
    run_autoproj_cli(:locate, :Locate, Hash[], *packages)
end
log(*args) click to toggle source
# File lib/autoproj/cli/main.rb, line 447
def log(*args)
    run_autoproj_cli(:log, :Log, Hash[], *args)
end
manifest(*name) click to toggle source
# File lib/autoproj/cli/main.rb, line 587
def manifest(*name)
    run_autoproj_cli(:manifest, :Manifest, Hash[silent: true], *name)
end
osdeps(*packages) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/autoproj/cli/main.rb, line 555
def query(query_string = nil)
    run_autoproj_cli(:query, :Query, Hash[], *Array(query_string))
end
reconfigure() click to toggle source
# File lib/autoproj/cli/main.rb, line 374
def reconfigure
    run_autoproj_cli(:reconfigure, :Reconfigure, Hash[])
end
reset(version_id) click to toggle source
# File lib/autoproj/cli/main.rb, line 460
def reset(version_id)
    run_autoproj_cli(:reset, :Reset, Hash[], version_id)
end
run_autoproj_cli(filename, classname, report_options, *args, tool_failure_mode: :exit_silent, **extra_options) click to toggle source
# File lib/autoproj/cli/main.rb, line 117
def run_autoproj_cli(filename, classname, report_options, *args, tool_failure_mode: :exit_silent, **extra_options)
    require "autoproj/cli/#{filename}"
    if options[:tool]
        Autobuild::Subprocess.transparent_mode = true
        Autobuild.silent = true
        Autobuild.color = false
        report_options[:silent] = true
        report_options[:on_package_failures] = tool_failure_mode
        extra_options[:silent] = true
    end

    Autoproj.report(**Hash[silent: !options[:debug], debug: options[:debug]].merge(report_options)) do
        options = self.options.dup
        # We use --local on the CLI but the APIs are expecting
        # only_local
        if options.has_key?("local")
            options[:only_local] = options.delete("local")
        end
        cli = CLI.const_get(classname).new
        begin
            *run_args, kw = cli.validate_options(args, options.merge(extra_options))
            kw = (kw || {}).transform_keys(&:to_sym)
            cli.run(*run_args, **kw)
        ensure
            if cli.respond_to?(:notify_env_sh_updated)
                cli.notify_env_sh_updated
            end
        end
    end
end
show(*packages) click to toggle source
# File lib/autoproj/cli/main.rb, line 393
def show(*packages)
    run_autoproj_cli(:show, :Show, Hash[], *packages)
end
status(*packages) click to toggle source
# File lib/autoproj/cli/main.rb, line 190
def status(*packages)
    run_autoproj_cli(:status, :Status, Hash[], *packages)
end
switch_config(*args) click to toggle source
# 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) click to toggle source
# File lib/autoproj/cli/main.rb, line 478
def tag(tag_name = nil, *packages)
    run_autoproj_cli(:tag, :Tag, Hash[], tag_name, *packages)
end
thor_options_to_optparse() click to toggle source

Generate a command line for Ops::Install, which has an internal option parser based on OptionParse (to be self-sufficient)

# File lib/autoproj/cli/main.rb, line 106
def thor_options_to_optparse
    flags = []
    %i[color progress debug interactive].each do |option|
        if options[option] then flags << "--#{option}"
        else
            flags << "--no-#{option}"
        end
    end
    flags
end
unpatch(*packages) click to toggle source
# File lib/autoproj/cli/main.rb, line 582
def unpatch(*packages)
    run_autoproj_cli(:patcher, :Patcher, Hash[], *packages, patch: false)
end
update(*packages) click to toggle source
# 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) click to toggle source
# File lib/autoproj/cli/main.rb, line 409
def version(*args)
    run_autoproj_cli(:version, :Version, Hash[], *args)
end
versions(*packages) click to toggle source
# File lib/autoproj/cli/main.rb, line 437
def versions(*packages)
    run_autoproj_cli(:versions, :Versions, Hash[], *packages, deps: true)
end
watch() click to toggle source
# File lib/autoproj/cli/main.rb, line 173
def watch
    run_autoproj_cli(:watch, :Watch, Hash[])
end
which(cmd) click to toggle source
# 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