Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
espresso
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
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
Eduardo Trujillo
espresso
Commits
4dda4957
Verified
Commit
4dda4957
authored
2 years ago
by
Eduardo Trujillo
Browse files
Options
Downloads
Patches
Plain Diff
refactor(config): Remove unused functions
parent
2d4752c8
No related branches found
Branches containing commit
No related tags found
1 merge request
!3
v2.0.0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/config.rs
+6
-58
6 additions, 58 deletions
src/config.rs
with
6 additions
and
58 deletions
src/config.rs
+
6
−
58
View file @
4dda4957
...
...
@@ -273,71 +273,19 @@ impl From<IndexStrategyConfig> for IndexStrategy {
}
}
/// Attempts to read a Config object from the specified path.
///
/// The configuration file is expected to be a TOML file.
pub
fn
from_file
<
P
:
AsRef
<
Path
>>
(
path
:
P
)
->
Result
<
Config
>
{
let
path
=
path
.as_ref
();
log
::
info!
(
"Reading config file from {}"
,
path
.display
());
let
contents
=
fs
::
read_to_string
(
path
)
.context
(
OpenConfig
{
path
})
?
;
let
config
=
toml
::
from_str
(
&
contents
);
config
.context
(
DeserializeConfig
{
path
})
}
/// Attempts to read a Config object from the specified paths.
pub
fn
from_paths
<
P
:
AsRef
<
Path
>>
(
paths
:
Vec
<
P
>
)
->
Result
<
Config
>
{
for
path
in
paths
{
if
path
.as_ref
()
.exists
()
{
return
from_file
(
path
);
}
}
Err
(
Error
::
NoValidPath
)
}
/// Attempts to read a Config object from the current directory.
///
/// The configuration file is expected to be a TOML file named `config.toml`.
pub
fn
from_current_dir
()
->
Result
<
Config
>
{
let
mut
current_path
=
env
::
current_dir
()
.context
(
GetCurrentDir
)
?
;
current_path
.push
(
"config.toml"
);
from_file
(
&
current_path
)
}
/// Similar to `from_paths`. Uses a default set of paths:
///
/// - `CURRENT_WORKING_DIRECTORY/config.toml`
/// - `/etc/CRATE/config.toml`
pub
fn
from_default_paths
()
->
Result
<
Config
>
{
let
mut
current_path
=
env
::
current_dir
()
.context
(
GetCurrentDir
)
?
;
current_path
.push
(
"config.toml"
);
let
mut
config_path
=
PathBuf
::
from
(
"/etc/"
);
config_path
.push
(
PKG_NAME
);
config_path
.push
(
"config.toml"
);
let
paths
=
vec!
[
current_path
,
config_path
];
from_paths
(
paths
)
}
#[cfg(test)]
mod
tests
{
use
super
::{
from_file
,
BundleConfig
,
Config
,
ServerConfig
,
StatsConfig
,
UnbundlerConfig
};
use
collective
::
config
::
from_file
;
use
super
::{
BundleConfig
,
Config
,
ServerConfig
,
StatsConfig
,
UnbundlerConfig
};
use
std
::
path
::{
Path
,
PathBuf
};
#[test]
fn
test_from_file
()
{
let
config
:
Config
=
from_file
(
&
Path
::
new
(
"config.sample.toml"
),
None
)
.unwrap
();
assert_eq!
(
from_file
(
&
Path
::
new
(
"config.sample.toml"
))
.unwrap
()
,
config
,
Config
{
stats
:
Some
(
StatsConfig
{
address
:
"127.0.0.1:8089"
.parse
()
.unwrap
(),
...
...
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