Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
K
kcfg
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
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
Qonfucius
kcfg
Commits
676674f9
Commit
676674f9
authored
3 years ago
by
Félix Lescaudey de Maneville
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring
parent
92d06882
No related branches found
No related tags found
No related merge requests found
Pipeline
#385030323
passed
3 years ago
Stage: build
Stage: test
Stage: build_doc
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/command_init.rs
+5
-6
5 additions, 6 deletions
src/command_init.rs
src/command_use.rs
+8
-8
8 additions, 8 deletions
src/command_use.rs
src/error.rs
+2
-0
2 additions, 0 deletions
src/error.rs
src/main.rs
+6
-3
6 additions, 3 deletions
src/main.rs
with
21 additions
and
17 deletions
src/command_init.rs
+
5
−
6
View file @
676674f9
...
...
@@ -49,9 +49,10 @@ impl FromStr for InitShellType {
///
/// # Returns
///
/// Return an error if the current path is unavailable (FileSystem error) or invalid.
/// A `String` containing the produced code is returned on success.
/// An error is returned if the current path is unavailable (FileSystem error) or invalid.
///
pub
fn
router
(
params
:
InitOptions
)
->
Result
<
()
,
KcfgError
>
{
pub
fn
router
(
params
:
InitOptions
)
->
Result
<
String
,
KcfgError
>
{
let
path
=
match
params
.custom_path
{
None
=>
{
let
current_path
=
std
::
env
::
current_exe
()
?
;
...
...
@@ -62,13 +63,11 @@ pub fn router(params: InitOptions) -> Result<(), KcfgError> {
}
Some
(
p
)
=>
p
,
};
let
res
=
match
params
.shell_type
{
Ok
(
match
params
.shell_type
{
InitShellType
::
Common
=>
init_common_full
(
&
path
),
InitShellType
::
Zsh
=>
init_zsh
(
&
path
),
InitShellType
::
Bash
=>
init_bash
(
&
path
),
};
print!
(
"{}"
,
res
);
Ok
(())
})
}
/// # Arguments
...
...
This diff is collapsed.
Click to expand it.
src/command_use.rs
+
8
−
8
View file @
676674f9
...
...
@@ -34,11 +34,10 @@ pub struct UseOptions {
input
:
Vec
<
String
>
,
}
pub
fn
router
(
params
:
UseOptions
)
->
Result
<
()
,
KcfgError
>
{
pub
fn
router
(
params
:
UseOptions
)
->
Result
<
String
,
KcfgError
>
{
// Check if params are empty
if
params
.input
.is_empty
()
{
println!
(
"export {}="
,
KUBECONFIG
);
return
Ok
(());
return
Ok
(
format!
(
"export {}="
,
KUBECONFIG
));
}
// Check the Path
...
...
@@ -69,13 +68,14 @@ pub fn router(params: UseOptions) -> Result<(), KcfgError> {
let
name
=
skip_none!
(
captured
.get
(
1
))
.as_str
()
.to_string
();
let
ext
=
skip_none!
(
captured
.get
(
2
))
.as_str
()
.to_string
();
if
starting_string
==
name
{
println!
(
"export {}={}/{}{}"
,
KUBECONFIG
,
path_str
,
name
,
ext
);
return
Ok
(());
return
Ok
(
format!
(
"export {}={}/{}{}"
,
KUBECONFIG
,
path_str
,
name
,
ext
));
}
if
name
.starts_with
(
&
format!
(
"{}."
,
starting_string
))
{
println!
(
"{}"
,
&
name
[
starting_string
.len
()
+
1
..
]);
return
Ok
(());
return
Ok
(
name
[
starting_string
.len
()
+
1
..
]
.to_string
());
}
}
Ok
((
))
Err
(
KcfgError
::
ConfigNotFound
(
params
.input
))
}
This diff is collapsed.
Click to expand it.
src/error.rs
+
2
−
0
View file @
676674f9
...
...
@@ -23,4 +23,6 @@ pub enum KcfgError {
#[source]
std
::
env
::
VarError
,
),
#[error(
"Could not find a config using {0:?} as input"
)]
ConfigNotFound
(
Vec
<
String
>
),
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
6
−
3
View file @
676674f9
...
...
@@ -3,7 +3,6 @@
//! kcfg
use
crate
::
error
::
KcfgError
;
use
clap
::{
AppSettings
,
Clap
};
mod
command_init
;
...
...
@@ -36,11 +35,15 @@ enum Command {
Use
(
command_use
::
UseOptions
),
}
fn
main
()
->
Result
<
(),
KcfgError
>
{
fn
main
()
{
let
opts
:
Opts
=
Opts
::
parse
();
match
opts
.command
{
let
res
=
match
opts
.command
{
Command
::
Init
(
params
)
=>
command_init
::
router
(
params
),
Command
::
Use
(
params
)
=>
command_use
::
router
(
params
),
};
match
res
{
Ok
(
code
)
=>
println!
(
"{}"
,
code
),
Err
(
e
)
=>
eprintln!
(
"Error: {}"
,
e
),
}
}
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