Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
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
nodes
typescript
duniter
Merge requests
!1333
Feat/dex
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Feat/dex
feat/dex
into
dev
Overview
0
Commits
5
Pipelines
0
Changes
83
Merged
Éloïs
requested to merge
feat/dex
into
dev
4 years ago
Overview
0
Commits
5
Pipelines
0
Changes
83
Expand
0
0
Merge request reports
Compare
dev
version 3
19c21bd4
4 years ago
version 2
12b3d117
4 years ago
version 1
dd3b2f96
4 years ago
dev (base)
and
latest version
latest version
4357eb07
5 commits,
4 years ago
version 3
19c21bd4
5 commits,
4 years ago
version 2
12b3d117
5 commits,
4 years ago
version 1
dd3b2f96
4 commits,
4 years ago
83 files
+
9322
−
122
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
83
Search (e.g. *.vue) (Ctrl+P)
rust-bins/duniter-dbex/src/cli.rs
0 → 100644
+
125
−
0
Options
// Copyright (C) 2020 Éloïs SANCHEZ.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use
std
::{
num
::
NonZeroUsize
,
path
::
PathBuf
,
str
::
FromStr
};
use
structopt
::
StructOpt
;
#[derive(Debug,
StructOpt)]
#[structopt(name
=
"duniter-dbex"
,
about
=
"Duniter databases explorer."
)]
pub
struct
Opt
{
/// Duniter profile name
#[structopt(short,
long)]
pub
profile
:
Option
<
String
>
,
/// Duniter home directory
#[structopt(short,
long,
parse(from_os_str))]
pub
home
:
Option
<
PathBuf
>
,
/// database
#[structopt(default_value
=
"bc_v1"
,
possible_values
=
&[
"bc_v1"
,
"bc_v2"
,
"mp_v1"
]
)]
pub
database
:
Database
,
#[structopt(subcommand)]
pub
cmd
:
SubCommand
,
}
#[derive(Debug)]
pub
enum
Database
{
BcV1
,
}
impl
FromStr
for
Database
{
type
Err
=
String
;
fn
from_str
(
s
:
&
str
)
->
Result
<
Self
,
Self
::
Err
>
{
match
s
{
"bc_v1"
=>
Ok
(
Self
::
BcV1
),
"bc_v2"
|
"mp_v1"
=>
unimplemented!
(),
_
=>
unreachable!
(),
}
}
}
#[derive(Debug,
StructOpt)]
pub
enum
SubCommand
{
/// Count collection entries
Count
{
collection
:
String
},
/// Get one value
Get
{
collection
:
String
,
key
:
String
},
/// Search values by criteria
Find
{
collection
:
String
,
#[structopt(short,
long)]
/// Key min
start
:
Option
<
String
>
,
#[structopt(short,
long)]
/// Key max
end
:
Option
<
String
>
,
/// Filter keys by a regular expression
#[structopt(short
=
"k"
,
long)]
key_regex
:
Option
<
String
>
,
/// Show keys only
#[structopt(long)]
keys_only
:
bool
,
/// Filter values by a regular expression
#[structopt(short
=
"v"
,
long)]
value_regex
:
Option
<
String
>
,
/// Maximum number of entries to be found (Slower because force sequential search)
#[structopt(short,
long)]
limit
:
Option
<
usize
>
,
/// Browse the collection upside down
#[structopt(short,
long)]
reverse
:
bool
,
/// Step by
#[structopt(long,
default_value
=
"1"
)]
step
:
NonZeroUsize
,
/// Output format
#[structopt(short,
long,
default_value
=
"table-json"
,
possible_values
=
&[
"csv"
,
"json"
,
"table-json"
,
"table-properties"
]
)]
output
:
OutputFormat
,
/// Pretty json (Only for output format json or table-json)
#[structopt(long)]
pretty
:
bool
,
/// Show only the specified properties
#[structopt(short,
long)]
properties
:
Vec
<
String
>
,
/// Export found data to a file
#[structopt(short,
long,
parse(from_os_str))]
file
:
Option
<
PathBuf
>
,
},
/// Show database schema
Schema
,
}
#[derive(Clone,
Copy,
Debug)]
pub
enum
OutputFormat
{
Table
,
TableJson
,
Json
,
Csv
,
}
impl
FromStr
for
OutputFormat
{
type
Err
=
String
;
fn
from_str
(
s
:
&
str
)
->
Result
<
Self
,
Self
::
Err
>
{
match
s
{
"csv"
=>
Ok
(
Self
::
Csv
),
"json"
=>
Ok
(
Self
::
Json
),
"table-properties"
=>
Ok
(
Self
::
Table
),
"table-json"
=>
Ok
(
Self
::
TableJson
),
_
=>
unreachable!
(),
}
}
}
Loading