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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LBMC
Hub
git_borg_linker
Commits
929f3a10
Verified
Commit
929f3a10
authored
2 years ago
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/config_structure.rs: add gblk_project_name section in config
parent
b5bcc552
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/config_structure.rs
+85
-0
85 additions, 0 deletions
src/config_structure.rs
with
85 additions
and
0 deletions
src/config_structure.rs
+
85
−
0
View file @
929f3a10
use
std
::{
path
::
PathBuf
,
process
::
exit
};
use
colored
::
Colorize
;
/// This module contains the structure of the gblk config file
use
serde_derive
::{
Deserialize
,
Serialize
};
use
crate
::
commit
;
/// /// Structure containing the global definition of the borg config file
#[derive(Debug,
Deserialize,
Serialize,
Clone)]
pub
struct
Config
{
pub
gblk_project_name
:
GblkName
,
pub
gblk_prune
:
Option
<
GblkConfig
>
,
pub
gblk_remote
:
Option
<
Vec
<
RemoteConfig
>>
,
}
impl
Config
{
pub
fn
new
(
global
:
bool
)
->
Config
{
Config
{
gblk_project_name
:
GblkName
::
new
(
global
),
gblk_prune
:
None
,
gblk_remote
:
None
,
}
}
pub
fn
new_named
(
name
:
&
str
)
->
Config
{
Config
{
gblk_project_name
:
GblkName
::
new_named
(
name
),
gblk_prune
:
None
,
gblk_remote
:
None
,
}
}
pub
fn
get_name
(
&
self
)
->
Option
<
String
>
{
self
.gblk_project_name.name
.clone
()
}
pub
fn
check_project_type
(
&
self
,
is_global
:
bool
,
path
:
&
PathBuf
)
->
()
{
if
is_global
{
if
&
self
.gblk_project_name.config_type
!=
"global"
{
eprintln!
(
"{}: The type of the config file {} is not global"
,
"error"
.red
(),
path
.display
()
);
exit
(
1
);
}
}
else
{
if
&
self
.gblk_project_name.config_type
!=
"local"
{
eprintln!
(
"{}: The type of the config file {} is not local"
,
"error"
.red
(),
path
.display
()
);
exit
(
1
);
}
}
}
}
/// Structure corresponding to the gblk prune config to automatically use
/// inside a project
#[derive(Debug,
Deserialize,
Serialize,
Clone)]
...
...
@@ -81,3 +127,42 @@ impl RemoteConfig {
}
}
}
/// Structure that store the current borg name for the project
#[derive(Debug,
Deserialize,
Serialize,
Clone)]
pub
struct
GblkName
{
pub
name
:
Option
<
String
>
,
pub
config_type
:
String
,
}
impl
GblkName
{
pub
fn
new
(
global
:
bool
)
->
GblkName
{
if
global
{
GblkName
{
name
:
None
,
config_type
:
String
::
from
(
"global"
),
}
}
else
{
let
(
borg_folder
,
_
)
=
commit
::
check_path
();
let
borg_folder
=
borg_folder
.canonicalize
()
.unwrap
();
let
name
=
borg_folder
.parent
()
.unwrap
()
.file_stem
()
.unwrap
()
.to_str
()
.unwrap
()
.to_string
();
GblkName
{
name
:
Some
(
name
),
config_type
:
String
::
from
(
"local"
),
}
}
}
pub
fn
new_named
(
name
:
&
str
)
->
GblkName
{
GblkName
{
name
:
Some
(
String
::
from
(
name
)),
config_type
:
String
::
from
(
"local"
),
}
}
}
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