Method: Fig::Command#run_fig

Defined in:
lib/fig/command.rb

#run_fig(argv, options = nil) ⇒ Object



30
31
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fig/command.rb', line 30

def run_fig(argv, options = nil)
  @suppress_further_error_messages = false

  begin
    @options = options || Fig::Command::Options.new()
    @options.process_command_line(argv)
  rescue Fig::UserInputError => error
    $stderr.puts error.to_s # Logging isn't set up yet.
    return Fig::Command::Action::EXIT_FAILURE
  end

  if not @options.exit_code.nil?
    return @options.exit_code
  end

  Fig::Logging.initialize_pre_configuration(
    @options.log_to_stdout(), @options.log_level(),
  )

  actions = @options.actions()
  if actions.empty?
    return handle_nothing_to_do
  end

  actions.each do
    |action|

    if action.execute_immediately_after_command_line_parse?
      # Note that the action doesn't get an execution context.
      return action.execute()
    end
  end

  @descriptor = @options.descriptor
  check_descriptor_requirement()
  if actions.any? {|action| not action.allow_both_descriptor_and_file? }
    ensure_descriptor_and_file_were_not_both_specified()
  end
  check_asset_options()

  configure()
  set_up_base_package()
  invoke_post_set_up_actions()

  context = ExecutionContext.new(
    @base_package,
    @synthetic_package_for_command_line,
    base_config(),
    @environment,
    @repository,
    @non_repository_packages,
    @working_directory_maintainer,
    @operating_system,
    @package_source_description,
    @package_load_path_description
  )

  actions.each do
    |action|

    action.execution_context = context

    exit_code = action.execute
    if exit_code != Fig::Command::Action::EXIT_SUCCESS
      return exit_code
    end
  end

  return Fig::Command::Action::EXIT_SUCCESS
end