Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ğ
Ğcli-v2s
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
Rust
Ğcli-v2s
Commits
ba2e3165
Commit
ba2e3165
authored
1 year ago
by
Hugo Trentesaux
Committed by
Hugo Trentesaux
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
WIP improve config loading
parent
5ecba798
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!7
Big refacto
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/conf.rs
+27
-3
27 additions, 3 deletions
src/conf.rs
src/data.rs
+1
-1
1 addition, 1 deletion
src/data.rs
src/main.rs
+4
-4
4 additions, 4 deletions
src/main.rs
with
32 additions
and
8 deletions
src/conf.rs
+
27
−
3
View file @
ba2e3165
use
crate
::
*
;
use
serde
::{
Deserialize
,
Serialize
};
const
APP_NAME
:
&
str
=
"gcli"
;
#[derive(Serialize,
Deserialize,
Debug)]
pub
struct
Config
{
version
:
u8
,
duniter_endpoint
:
String
,
indexer_endpoint
:
String
,
}
impl
std
::
default
::
Default
for
Config
{
fn
default
()
->
Self
{
Self
{
version
:
0
,
duniter_endpoint
:
String
::
from
(
"ws://localhost:9944"
),
indexer_endpoint
:
String
::
from
(
"http://localhost:8080/v1/graphql"
),
}
}
}
/// load config file and manage error if could not
pub
fn
load_conf
()
->
Config
{
match
confy
::
load
(
APP_NAME
,
None
)
{
Ok
(
cfg
)
=>
cfg
,
Err
(
e
)
=>
{
log
::
warn!
(
"met error while loading config file"
);
log
::
error!
(
"{}"
,
e
);
log
::
info!
(
"removing the old conf file and creating a new one"
);
let
cfg
=
Config
::
default
();
confy
::
store
(
APP_NAME
,
None
,
&
cfg
)
.expect
(
"unable to write default config"
);
cfg
}
}
}
#[derive(Clone,
Default,
Debug,
clap::Parser)]
pub
enum
Subcommand
{
#[default]
/// Show config path
Where
,
/// Show config
Show
,
}
/// handle conf command
pub
fn
handle_command
(
data
:
Data
,
command
:
Subcommand
)
->
anyhow
::
Result
<
()
>
{
// match subcommand
match
command
{
Subcommand
::
Show
=>
{
Subcommand
::
Where
=>
{
println!
(
"{}"
,
confy
::
get_configuration_file_path
(
APP_NAME
,
None
)
?
.display
());
}
Subcommand
::
Show
=>
{
println!
(
"{:?}"
,
data
.cfg
);
}
};
...
...
This diff is collapsed.
Click to expand it.
src/data.rs
+
1
−
1
View file @
ba2e3165
...
...
@@ -45,7 +45,7 @@ impl Data {
pub
fn
new
(
args
:
Args
)
->
Self
{
Self
{
args
,
cfg
:
conf
y
::
load
(
"gcli"
,
None
)
.expect
(
"must be able to build config"
),
cfg
:
conf
::
load
_conf
(
),
token_decimals
:
0
,
token_symbol
:
"tokens"
.into
(),
..
Default
::
default
()
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
4
−
4
View file @
ba2e3165
...
...
@@ -75,8 +75,8 @@ pub struct Args {
/// Subcommands
#[clap(subcommand)]
pub
subcommand
:
Subcommand
,
///
Indexer URL
#[clap(short,
long,
default_value
=
"
http://localhost:8080/v1/graphql
"
)]
///
Overwrite indexer endpoint
#[clap(short,
long,
default_value
=
""
)]
indexer
:
String
,
/// Do not use indexer
#[clap(long)]
...
...
@@ -91,8 +91,8 @@ pub struct Args {
/// Address
#[clap(short,
long)]
address
:
Option
<
String
>
,
///
W
ebsocket RPC endpoint
#[clap(short,
long,
default_value
=
"
ws://localhost:9944
"
)]
///
Overwrite duniter w
ebsocket RPC endpoint
#[clap(short,
long,
default_value
=
""
)]
url
:
String
,
}
...
...
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