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
2aec9bec
Commit
2aec9bec
authored
1 year ago
by
Hugo Trentesaux
Committed by
Hugo Trentesaux
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
WIP move address to conf
parent
6ccda071
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
doc/example.md
+13
-0
13 additions, 0 deletions
doc/example.md
src/conf.rs
+5
-0
5 additions, 0 deletions
src/conf.rs
src/data.rs
+37
-24
37 additions, 24 deletions
src/data.rs
with
55 additions
and
24 deletions
doc/example.md
+
13
−
0
View file @
2aec9bec
...
...
@@ -23,6 +23,19 @@ with derivations:
-
`//Charlie`
-
...
## Configuration
It can be handful to use Gcli with a configuration file to avoid passing arguments on every command.
```
sh
# show config commands
gcli config
# show where config file is stored
gcli config where
# save config to use gdev network for next commands
gcli
--network
gdev config save
```
## Commands
```
sh
...
...
This diff is collapsed.
Click to expand it.
src/conf.rs
+
5
−
0
View file @
2aec9bec
...
...
@@ -5,8 +5,12 @@ const APP_NAME: &str = "gcli";
#[derive(Serialize,
Deserialize,
Debug)]
pub
struct
Config
{
// duniter endpoint
pub
duniter_endpoint
:
String
,
// indexer endpoint
pub
indexer_endpoint
:
String
,
// user address
pub
address
:
Option
<
AccountId
>
,
}
impl
std
::
default
::
Default
for
Config
{
...
...
@@ -14,6 +18,7 @@ impl std::default::Default for Config {
Self
{
duniter_endpoint
:
String
::
from
(
data
::
LOCAL_DUNITER_ENDPOINT
),
indexer_endpoint
:
String
::
from
(
data
::
LOCAL_INDEXER_ENDPOINT
),
address
:
None
,
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/data.rs
+
37
−
24
View file @
2aec9bec
...
...
@@ -33,8 +33,6 @@ pub struct Data {
pub
client
:
Option
<
Client
>
,
// graphql to duniter-indexer
pub
indexer
:
Option
<
Indexer
>
,
// user address
pub
address
:
Option
<
AccountId
>
,
// user keypair
pub
keypair
:
Option
<
Pair
>
,
// user identity index
...
...
@@ -79,7 +77,7 @@ impl Data {
self
.indexer
.as_ref
()
.expect
(
"indexer is not set up"
)
}
pub
fn
address
(
&
self
)
->
AccountId
{
self
.address
.clone
()
.expect
(
"an address is needed"
)
self
.
cfg.
address
.clone
()
.expect
(
"an address is needed"
)
}
pub
fn
keypair
(
&
self
)
->
Pair
{
self
.keypair
.clone
()
.expect
(
"a keypair is needed"
)
...
...
@@ -99,6 +97,7 @@ impl Data {
// --- mutators ---
/// use arguments to overwrite config
pub
fn
overwrite_from_args
(
mut
self
)
->
Self
{
// network
if
let
Some
(
network
)
=
self
.args.network
.clone
()
{
// a network was provided as arugment
match
&
network
[
..
]
{
...
...
@@ -131,40 +130,54 @@ impl Data {
}
}
}
// duniter endpoint
if
let
Some
(
duniter_endpoint
)
=
self
.args.url
.clone
()
{
self
.cfg.duniter_endpoint
=
duniter_endpoint
;
}
// indexer endpoint
if
let
Some
(
indexer_endpoint
)
=
self
.args.indexer
.clone
()
{
self
.cfg.indexer_endpoint
=
indexer_endpoint
}
// secret
if
self
.args.secret
.is_some
()
{
self
=
self
.build_keypair
();
}
// address
if
self
.args.address
.is_some
()
{
self
=
self
.build_address
();
}
self
}
///
force
an address if needed
///
ask user to input
an address if needed
pub
fn
build_address
(
mut
self
)
->
Self
{
self
.address
=
Some
(
get_keys
(
if
self
.cfg.address
.is_none
()
{
self
.cfg.address
=
Some
(
get_keys
(
self
.args.secret_format
,
&
self
.args.address
,
&
self
.args.secret
,
NeededKeys
::
Public
,
)
.expect
(
"needed"
)
.0
.expect
(
"needed"
),
);
}
self
}
/// ask user to input a keypair if needed
pub
fn
build_keypair
(
mut
self
)
->
Self
{
if
self
.keypair
.is_none
()
{
let
(
address
,
keypair
)
=
get_keys
(
self
.args.secret_format
,
&
self
.args.address
,
&
self
.args.secret
,
NeededKeys
::
Public
,
NeededKeys
::
Secret
,
)
.expect
(
"needed"
)
.0
.expect
(
"needed"
),
);
self
}
/// force a keypair if needed
pub
fn
build_keypair
(
mut
self
)
->
Self
{
let
(
address
,
keypair
)
=
get_keys
(
self
.args.secret_format
,
&
self
.args.address
,
&
self
.args.secret
,
NeededKeys
::
Secret
,
)
.expect
(
"needed"
);
self
.address
=
address
;
self
.keypair
=
keypair
;
.expect
(
"needed"
);
self
.cfg.address
=
address
;
self
.keypair
=
keypair
;
}
self
}
/// build a client from url
...
...
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