Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ftl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Pope
ftl
Commits
b13ab85b
Commit
b13ab85b
authored
5 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Patches
Plain Diff
Merge patch config files
parent
f6adcb24
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/cpp/src/configuration.cpp
+35
-12
35 additions, 12 deletions
common/cpp/src/configuration.cpp
with
35 additions
and
12 deletions
common/cpp/src/configuration.cpp
+
35
−
12
View file @
b13ab85b
...
...
@@ -94,26 +94,49 @@ optional<string> locateFile(const string &name, const vector<string> &paths) {
return
{};
}
/**
* Combine one json config with another patch json config.
*/
static
bool
mergeConfig
(
const
string
&
path
)
{
ifstream
i
;
i
.
open
(
path
);
if
(
i
.
is_open
())
{
json
t
;
i
>>
t
;
config
.
merge_patch
(
t
);
return
true
;
}
else
{
return
false
;
}
}
/**
* Find and load a JSON configuration file
*/
static
bool
findConfiguration
(
const
string
&
file
,
const
vector
<
string
>
&
paths
,
const
std
::
string
&
app
)
{
ifstream
i
;
bool
found
=
false
;
if
(
file
!=
""
)
i
.
open
(
file
);
if
(
!
i
.
is_open
())
{
auto
f
=
locateFile
(
"config.json"
,
paths
);
if
(
!
f
)
return
false
;
i
.
open
(
*
f
);
}
found
|=
mergeConfig
(
FTL_GLOBAL_CONFIG_ROOT
"/config.json"
);
found
|=
mergeConfig
(
FTL_LOCAL_CONFIG_ROOT
"/config.json"
);
found
|=
mergeConfig
(
"./config.json"
);
if
(
!
i
.
is_open
())
return
false
;
for
(
auto
p
:
paths
)
{
if
(
is_directory
(
p
))
{
found
|=
mergeConfig
(
p
+
"/config.json"
);
}
}
i
>>
config
;
config
=
config
[
app
];
return
true
;
if
(
file
!=
""
)
{
found
|=
mergeConfig
(
file
);
}
if
(
found
)
{
config
=
config
[
app
];
return
true
;
}
else
{
return
false
;
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment