Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
git_borg_linker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LBMC
Hub
git_borg_linker
Commits
a5401655
Verified
Commit
a5401655
authored
Jan 13, 2023
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/configt.rs: minor change of some functions
parent
f90d42fe
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/configt.rs
+54
-24
54 additions, 24 deletions
src/configt.rs
with
54 additions
and
24 deletions
src/configt.rs
+
54
−
24
View file @
a5401655
use
crate
::
commit
;
use
crate
::
commit
;
use
crate
::
config_structure
::{
Config
,
GblkConfig
};
use
crate
::
config_structure
::{
Config
,
GblkConfig
,
RemoteConfig
};
use
crate
::
prune
::{
new_prune
,
prune_launcher
};
use
crate
::
prune
::{
new_prune
,
prune_launcher
};
use
clap
::
Args
;
use
clap
::
Args
;
use
colored
::
Colorize
;
use
colored
::
Colorize
;
...
@@ -51,28 +51,27 @@ pub(crate) struct PartialPrune {
...
@@ -51,28 +51,27 @@ pub(crate) struct PartialPrune {
/// # Return
/// # Return
/// A pathbuf variable containing the location of borg config file for the
/// A pathbuf variable containing the location of borg config file for the
/// current project
/// current project
fn
get_borgconfig
()
->
PathBuf
{
pub
fn
get_borgconfig
()
->
Option
<
PathBuf
>
{
let
(
mut
config_path
,
_
)
=
commit
::
check_path
();
let
(
mut
config_path
,
_
)
=
commit
::
check_path
();
config_path
.push
(
"config"
);
config_path
.push
(
"config"
);
if
!
config_path
.is_file
()
{
if
!
config_path
.is_file
()
{
eprintln!
(
"{} not found !"
,
config_path
.to_str
()
.unwrap
());
return
None
;
exit
(
1
);
}
}
config_path
Some
(
config_path
)
}
}
/// Get the global configuration for gblk
/// Get the global configuration for gblk
/// # Return
/// # Return
/// - The path where the global location of the gblk configuration should be set
/// - The path where the global location of the gblk configuration should be set
fn
get_global_config
()
->
PathBuf
{
pub
fn
get_global_config
()
->
Option
<
PathBuf
>
{
let
mut
global_config
=
match
home
::
home_dir
()
{
let
global_config
=
match
home
::
home_dir
()
{
Some
(
path
)
=>
path
,
Some
(
path
)
=>
{
None
=>
{
let
mut
tmp
=
path
;
eprintln!
(
"{} global config not found!"
,
"error:"
.red
());
tmp
.push
(
".gblkconfig"
);
exit
(
1
);
Some
(
tmp
)
}
}
None
=>
None
,
};
};
global_config
.push
(
".gblkconfig"
);
global_config
global_config
}
}
...
@@ -84,9 +83,21 @@ fn get_global_config() -> PathBuf {
...
@@ -84,9 +83,21 @@ fn get_global_config() -> PathBuf {
/// The path containing the local of global configuration
/// The path containing the local of global configuration
fn
get_config
(
global
:
bool
)
->
PathBuf
{
fn
get_config
(
global
:
bool
)
->
PathBuf
{
if
global
{
if
global
{
get_global_config
()
match
get_global_config
()
{
Some
(
path
)
=>
path
,
None
=>
{
eprintln!
(
"local config not found !"
);
exit
(
1
);
}
}
}
else
{
}
else
{
get_borgconfig
()
match
get_borgconfig
()
{
Some
(
path
)
=>
path
,
None
=>
{
eprintln!
(
"global config not found !"
);
exit
(
1
);
}
}
}
}
}
}
...
@@ -96,7 +107,7 @@ fn get_config(global: bool) -> PathBuf {
...
@@ -96,7 +107,7 @@ fn get_config(global: bool) -> PathBuf {
/// only the local one
/// only the local one
/// # Return
/// # Return
/// The parsed toml file
/// The parsed toml file
fn
parse_toml
(
global
:
bool
)
->
Config
{
pub
fn
parse_toml
(
global
:
bool
)
->
Config
{
let
config_file
=
get_config
(
global
);
let
config_file
=
get_config
(
global
);
let
rcontent
=
std
::
fs
::
read_to_string
(
&
config_file
);
let
rcontent
=
std
::
fs
::
read_to_string
(
&
config_file
);
let
content
=
match
rcontent
{
let
content
=
match
rcontent
{
...
@@ -113,6 +124,7 @@ fn parse_toml(global: bool) -> Config {
...
@@ -113,6 +124,7 @@ fn parse_toml(global: bool) -> Config {
return
Config
{
return
Config
{
repository
:
None
,
repository
:
None
,
gblk_prune
:
None
,
gblk_prune
:
None
,
gblk_remote
:
None
,
};
};
}
}
let
re
=
Regex
::
new
(
"id = (?P<first>[0-9a-z]+)
\\
W"
)
.unwrap
();
let
re
=
Regex
::
new
(
"id = (?P<first>[0-9a-z]+)
\\
W"
)
.unwrap
();
...
@@ -318,16 +330,11 @@ fn toml_to_string(config: &Config) -> String {
...
@@ -318,16 +330,11 @@ fn toml_to_string(config: &Config) -> String {
nc
nc
}
}
/// Function
that update the current gblk config file for the project folder
/// Function
used to write a configuration file
/// # Arguments
/// # Arguments
/// - `key` : The key to update
/// - `config` The structure representing the configuration file to write
/// - `value`: The value of the key to update
/// - `global`: A boolean indicating whether or not to write the configuration file
/// - `global: A bolean indicating whether to update the global or the local configuration
pub
fn
write_config
(
config
:
&
Config
,
global
:
bool
)
{
pub
fn
update_config
(
key
:
&
str
,
value
:
&
str
,
global
:
bool
)
->
()
{
let
mut
config
=
parse_toml
(
global
);
let
mut
gblk_config
:
GblkConfig
=
get_gblkconfig
(
&
config
);
update_val
(
&
mut
gblk_config
,
key
,
value
);
config
.gblk_prune
=
Some
(
gblk_config
);
let
gblk_str
=
toml_to_string
(
&
config
);
let
gblk_str
=
toml_to_string
(
&
config
);
let
config_file
=
get_config
(
global
);
let
config_file
=
get_config
(
global
);
let
kind
=
if
global
{
"global"
}
else
{
"local"
};
let
kind
=
if
global
{
"global"
}
else
{
"local"
};
...
@@ -348,6 +355,29 @@ pub fn update_config(key: &str, value: &str, global: bool) -> () {
...
@@ -348,6 +355,29 @@ pub fn update_config(key: &str, value: &str, global: bool) -> () {
};
};
}
}
/// Function that update the current gblk config file for the project folder
/// # Arguments
/// - `key` : The key to update
/// - `value`: The value of the key to update
/// - `global: A bolean indicating whether to update the global or the local configuration
pub
fn
update_config
(
key
:
&
str
,
value
:
&
str
,
global
:
bool
)
->
()
{
let
mut
config
=
parse_toml
(
global
);
let
mut
gblk_config
:
GblkConfig
=
get_gblkconfig
(
&
config
);
update_val
(
&
mut
gblk_config
,
key
,
value
);
config
.gblk_prune
=
Some
(
gblk_config
);
config
.gblk_remote
=
Some
(
vec!
[
RemoteConfig
{
name
:
String
::
from
(
"lol"
),
url
:
String
::
from
(
"test"
),
},
RemoteConfig
{
name
:
String
::
from
(
"lol2"
),
url
:
String
::
from
(
"test2"
),
},
]);
write_config
(
&
config
,
global
);
}
/// Function that remove the current gblk config file for the project folder
/// Function that remove the current gblk config file for the project folder
/// for a given arguments
/// for a given arguments
/// # Arguments
/// # Arguments
...
...
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