master
cpp 54 lines 1.15 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 EnvironmentOptions.cpp
8
9 --*/
10 #include "precomp.h"
11 #include "EnvironmentOptions.h"
12
13 namespace wsl::windows::wslc {
14
15 void ApplyEnvironmentOptions(argument::ArgMap& target, const std::vector<Argument>& definedArgs) noexcept
16 try
17 {
18 for (const auto& arg : definedArgs)
19 {
20 // Lowest-precedence: skip args already set by the caller.
21 if (target.Contains(arg.Type()))
22 {
23 continue;
24 }
25
26 for (const auto& binding : c_envBindings)
27 {
28 if (binding.Type != arg.Type())
29 {
30 continue;
31 }
32
33 auto value = wsl::windows::common::wslutil::ReadEnvironmentVariable(binding.Name);
34 if (!value.has_value())
35 {
36 continue;
37 }
38
39 if (arg.Kind() == Kind::Flag)
40 {
41 target.Add(arg.Type(), true);
42 }
43 else if (arg.Kind() == Kind::Value)
44 {
45 target.Add(arg.Type(), std::move(*value));
46 }
47
48 break;
49 }
50 }
51 }
52 CATCH_LOG()
53
54 } // namespace wsl::windows::wslc