Class: Autoproj::CLI::Which

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

Instance Method Summary collapse

Constructor Details

#initializeWhich

Returns a new instance of Which.



9
10
11
12
13
14
15
16
17
# File 'lib/autoproj/cli/which.rb', line 9

def initialize
    @root_dir = Autoproj.find_workspace_dir
    unless @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

Instance Method Details

#load_cached_envObject



19
20
21
22
23
24
25
# File 'lib/autoproj/cli/which.rb', line 19

def load_cached_env
    env = Ops.load_cached_env(@root_dir)
    return unless env

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

#run(cmd, use_cached_env: Ops.watch_running?(@root_dir)) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/autoproj/cli/which.rb', line 27

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

    unless 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