Sha256: 63331e3c775d00df7712be10d3bed1119876c432dab566950b872d03c0b9f5e3

Contents?: true

Size: 1.79 KB

Versions: 26

Compression:

Stored size: 1.79 KB

Contents

require 'autoproj'
require 'autoproj/ops/cached_env'
require 'autoproj/ops/which'
require 'autoproj/ops/watch'

module Autoproj
    module CLI
        class Which
            def initialize
                @root_dir = Autoproj.find_workspace_dir
                if !@root_dir
                    require 'autoproj/workspace'
                    # Will do all sorts of error reporting,
                    # or may be able to resolve
                    @root_dir = Workspace.default.root_dir
                end
            end

            def load_cached_env
                env = Ops.load_cached_env(@root_dir)
                return if !env

                Autobuild::Environment.
                    environment_from_export(env, ENV)
            end

            def run(cmd, use_cached_env: Ops.watch_running?(@root_dir))
                if use_cached_env
                    env = load_cached_env
                end

                if !env
                    require 'autoproj'
                    require 'autoproj/cli/inspection_tool'
                    ws = Workspace.from_dir(@root_dir)
                    loader = InspectionTool.new(ws)
                    loader.initialize_and_load
                    loader.finalize_setup(Array.new)
                    env = ws.full_env.resolved_env
                end

                path = env['PATH'].split(File::PATH_SEPARATOR)
                puts Ops.which(cmd, path_entries: path)
            rescue ExecutableNotFound => e
                require 'autoproj' # make sure everything is available for error reporting
                raise CLIInvalidArguments, e.message, e.backtrace
            rescue Exception
                require 'autoproj' # make sure everything is available for error reporting
                raise
            end
        end
    end
end


Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
autoproj-2.14.0 lib/autoproj/cli/which.rb
autoproj-2.13.0 lib/autoproj/cli/which.rb
autoproj-2.12.1 lib/autoproj/cli/which.rb
autoproj-2.12.0 lib/autoproj/cli/which.rb
autoproj-2.11.0 lib/autoproj/cli/which.rb
autoproj-2.10.2 lib/autoproj/cli/which.rb
autoproj-2.10.1 lib/autoproj/cli/which.rb
autoproj-2.10.0 lib/autoproj/cli/which.rb
autoproj-2.9.0 lib/autoproj/cli/which.rb
autoproj-2.8.8 lib/autoproj/cli/which.rb
autoproj-2.8.7 lib/autoproj/cli/which.rb
autoproj-2.8.6 lib/autoproj/cli/which.rb
autoproj-2.8.5 lib/autoproj/cli/which.rb
autoproj-2.8.5.b1 lib/autoproj/cli/which.rb
autoproj-2.8.4 lib/autoproj/cli/which.rb
autoproj-2.8.3 lib/autoproj/cli/which.rb
autoproj-2.8.2 lib/autoproj/cli/which.rb
autoproj-2.8.1 lib/autoproj/cli/which.rb
autoproj-2.8.0 lib/autoproj/cli/which.rb
autoproj-2.7.1 lib/autoproj/cli/which.rb