Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
argo
cuttr
Commits
f0c888f1
Commit
f0c888f1
authored
Sep 21, 2018
by
Alexis Janon
Browse files
Show module integration
parent
ed87d125
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/configuration/mod.rs
View file @
f0c888f1
...
...
@@ -2,17 +2,20 @@ pub mod sysfscontroller;
use
self
::
sysfscontroller
::{
get_sys_fs_controllers
,
SysFsControllerList
};
use
error
::
*
;
use
serde_json
;
#[derive(Clone,
Eq,
PartialEq,
Debug,
Serialize,
Deserialize)]
pub
struct
Conf
iguration
{
controllers
:
SysFsControllerList
,
pub
struct
Sys
Conf
{
pub
controllers
:
SysFsControllerList
,
}
// TODO: use the same controller as in main?
pub
fn
get_configuration
()
->
Result
<
String
>
{
let
conf
=
Configuration
{
controllers
:
get_sys_fs_controllers
()
?
,
};
serde_json
::
to_string
(
&
conf
)
.map_err
(
Error
::
from
)
pub
fn
get_configuration
()
->
Result
<
SysConf
>
{
Ok
(
SysConf
{
controllers
:
get_sys_fs_controllers
()
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not retrieve controllers: {}"
,
err
.to_string
()
))
})
?
,
})
}
src/lib.rs
View file @
f0c888f1
...
...
@@ -15,3 +15,4 @@ pub mod configuration;
pub
mod
error
;
pub
mod
parsing
;
pub
mod
result
;
pub
mod
show
;
src/main.rs
View file @
f0c888f1
...
...
@@ -4,7 +4,7 @@ extern crate clap;
extern
crate
cuttr
;
extern
crate
log4rs
;
use
clap
::{
App
,
Arg
,
SubCommand
};
use
clap
::{
App
,
Arg
,
ArgMatches
,
SubCommand
};
use
cuttr
::
configuration
::
sysfscontroller
::{
get_sys_fs_controllers
,
SysFsControllerList
};
use
cuttr
::
error
::
*
;
use
cuttr
::
result
::
*
;
...
...
@@ -58,11 +58,15 @@ fn exec() -> Result<CommandResult> {
)
.subcommand
(
SubCommand
::
with_name
(
"show"
)
.about
(
"Shows information about the system"
)
.arg
(
Arg
::
with_name
(
"TYPE"
)
.help
(
"The information type requested"
)
.possible_values
(
&
[
"configuration"
])
.required
(
true
),
.subcommand
(
SubCommand
::
with_name
(
"configuration"
)
.help
(
"Show configuration"
))
.subcommand
(
SubCommand
::
with_name
(
"slice"
)
.help
(
"Show key/value pairs of a given slice"
)
.arg
(
Arg
::
with_name
(
"JSON"
)
.help
(
"JSON slice and key/value list"
)
.required
(
true
),
),
),
)
.get_matches
();
let
level
=
match
LOG_DEFAULT
+
matches
.occurrences_of
(
"v"
)
as
i64
...
...
@@ -84,7 +88,7 @@ fn exec() -> Result<CommandResult> {
})
?
);
match
matches
.subcommand
()
{
(
"transaction"
,
Some
(
sub_m
))
=>
transaction
(
sub_m
.value_of
(
"JSON"
)
.unwrap
(),
controllers
),
(
"show"
,
Some
(
sub_m
))
=>
show
(
sub_m
.value_of
(
"TYPE"
)
.unwrap
()
),
(
"show"
,
Some
(
sub_m
))
=>
show
(
sub_m
),
(
name
,
_
)
=>
Err
(
Error
::
from
(
format!
(
"Unknown subcommand: {}"
,
name
))),
}
}
...
...
@@ -104,19 +108,29 @@ fn transaction(json: &str, controllers: Rc<SysFsControllerList>) -> Result<Comma
}
}
fn
show
(
info_type
:
&
str
)
->
Result
<
CommandResult
>
{
match
info_type
{
"configuration"
=>
{
let
configuration
=
configuration
::
get_
configuration
()
.map_err
(|
err
|
{
fn
show
(
matches
:
&
ArgMatches
)
->
Result
<
CommandResult
>
{
match
matches
.subcommand
()
{
(
"configuration"
,
_
)
=>
{
let
configuration
=
show
::
configuration
()
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not
r
et
rieve
configuration: {}"
,
"Could not
g
et
serialized
configuration: {}"
,
err
.to_string
()
))
})
?
;
println!
(
"{}"
,
configuration
);
Ok
(
CommandResult
::
from
(()))
}
_
=>
Err
(
Error
::
from
(
format!
(
"Unknown info type: {}"
,
info_type
))),
(
"slice"
,
Some
(
sub_m
))
=>
{
let
slice_info
=
show
::
slice
(
sub_m
.value_of
(
"JSON"
)
.unwrap
())
.map_err
(|
err
|
{
Error
::
from
(
format!
(
"Could not get serialized slice information: {}"
,
err
.to_string
()
))
})
?
;
println!
(
"{}"
,
slice_info
);
Ok
(
CommandResult
::
from
(()))
}
(
name
,
_
)
=>
Err
(
Error
::
from
(
format!
(
"Unknown show subcommand: {}"
,
name
))),
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment