Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
silkaj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
silkaj
Commits
20e00de3
Commit
20e00de3
authored
2 years ago
by
Moul
Browse files
Options
Downloads
Patches
Plain Diff
Move MutuallyExclusiveOption from cli_tools to tools (
#330
)
parent
7fc59772
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
silkaj/cli_tools.py
+0
-40
0 additions, 40 deletions
silkaj/cli_tools.py
silkaj/money/transfer.py
+6
-6
6 additions, 6 deletions
silkaj/money/transfer.py
silkaj/tools.py
+25
-0
25 additions, 0 deletions
silkaj/tools.py
with
31 additions
and
46 deletions
silkaj/cli_tools.py
deleted
100644 → 0
+
0
−
40
View file @
7fc59772
# Copyright 2016-2022 Maël Azimi <m.a@moul.re>
#
# Silkaj 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.
#
# Silkaj 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 Silkaj. If not, see <https://www.gnu.org/licenses/>.
from
typing
import
Any
from
click
import
Context
,
Option
,
UsageError
# pylint: disable=too-few-public-methods
class
MutuallyExclusiveOption
(
Option
):
def
__init__
(
self
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
None
:
self
.
mutually_exclusive
=
set
(
kwargs
.
pop
(
"
mutually_exclusive
"
,
[]))
_help
=
kwargs
.
get
(
"
help
"
,
""
)
if
self
.
mutually_exclusive
:
ex_str
=
"
,
"
.
join
(
self
.
mutually_exclusive
)
kwargs
[
"
help
"
]
=
f
"
{
_help
}
NOTE: This argument is mutually exclusive with arguments: [
{
ex_str
}
].
"
super
().
__init__
(
*
args
,
**
kwargs
)
def
handle_parse_result
(
self
,
ctx
:
Context
,
opts
:
Any
,
args
:
Any
)
->
Any
:
if
self
.
mutually_exclusive
.
intersection
(
opts
)
and
self
.
name
in
opts
:
arguments
=
"
,
"
.
join
(
self
.
mutually_exclusive
)
raise
UsageError
(
f
"
Usage: `
{
self
.
name
}
` is mutually exclusive with arguments `
{
arguments
}
`.
"
)
return
super
().
handle_parse_result
(
ctx
,
opts
,
args
)
This diff is collapsed.
Click to expand it.
silkaj/money/transfer.py
+
6
−
6
View file @
20e00de3
...
@@ -31,7 +31,7 @@ from duniterpy.documents import (
...
@@ -31,7 +31,7 @@ from duniterpy.documents import (
)
)
from
duniterpy.key
import
SigningKey
from
duniterpy.key
import
SigningKey
from
silkaj
import
auth
,
cli_tools
,
network
,
public_key
,
tools
,
tui
from
silkaj
import
auth
,
network
,
public_key
,
tools
,
tui
from
silkaj.blockchain
import
tools
as
bc_tools
from
silkaj.blockchain
import
tools
as
bc_tools
from
silkaj.constants
import
(
from
silkaj.constants
import
(
CENT_MULT_TO_UNIT
,
CENT_MULT_TO_UNIT
,
...
@@ -67,7 +67,7 @@ NBR_ISSUERS = 1
...
@@ -67,7 +67,7 @@ NBR_ISSUERS = 1
multiple
=
True
,
multiple
=
True
,
type
=
click
.
FloatRange
(
MINIMAL_ABSOLUTE_TX_AMOUNT
),
type
=
click
.
FloatRange
(
MINIMAL_ABSOLUTE_TX_AMOUNT
),
help
=
f
"
Quantitative amount(s):
\n
-a <amount>
\n
Minimum amount is
{
MINIMAL_ABSOLUTE_TX_AMOUNT
}
.
"
,
help
=
f
"
Quantitative amount(s):
\n
-a <amount>
\n
Minimum amount is
{
MINIMAL_ABSOLUTE_TX_AMOUNT
}
.
"
,
cls
=
cli_
tools
.
MutuallyExclusiveOption
,
cls
=
tools
.
MutuallyExclusiveOption
,
mutually_exclusive
=
[
"
amountsud
"
,
"
allsources
"
,
"
file_path
"
],
mutually_exclusive
=
[
"
amountsud
"
,
"
allsources
"
,
"
file_path
"
],
)
)
@click.option
(
@click.option
(
...
@@ -77,14 +77,14 @@ NBR_ISSUERS = 1
...
@@ -77,14 +77,14 @@ NBR_ISSUERS = 1
multiple
=
True
,
multiple
=
True
,
type
=
click
.
FloatRange
(
MINIMAL_RELATIVE_TX_AMOUNT
),
type
=
click
.
FloatRange
(
MINIMAL_RELATIVE_TX_AMOUNT
),
help
=
f
"
Relative amount(s):
\n
-d <amount_UD>
\n
Minimum amount is
{
MINIMAL_RELATIVE_TX_AMOUNT
}
"
,
help
=
f
"
Relative amount(s):
\n
-d <amount_UD>
\n
Minimum amount is
{
MINIMAL_RELATIVE_TX_AMOUNT
}
"
,
cls
=
cli_
tools
.
MutuallyExclusiveOption
,
cls
=
tools
.
MutuallyExclusiveOption
,
mutually_exclusive
=
[
"
amounts
"
,
"
allsources
"
,
"
file_path
"
],
mutually_exclusive
=
[
"
amounts
"
,
"
allsources
"
,
"
file_path
"
],
)
)
@click.option
(
@click.option
(
"
--allSources
"
,
"
--allSources
"
,
is_flag
=
True
,
is_flag
=
True
,
help
=
"
Send all sources to one recipient
"
,
help
=
"
Send all sources to one recipient
"
,
cls
=
cli_
tools
.
MutuallyExclusiveOption
,
cls
=
tools
.
MutuallyExclusiveOption
,
mutually_exclusive
=
[
"
amounts
"
,
"
amountsud
"
,
"
file_path
"
],
mutually_exclusive
=
[
"
amounts
"
,
"
amountsud
"
,
"
file_path
"
],
)
)
@click.option
(
@click.option
(
...
@@ -96,7 +96,7 @@ NBR_ISSUERS = 1
...
@@ -96,7 +96,7 @@ NBR_ISSUERS = 1
Sending to many recipients is possible:
\n\
Sending to many recipients is possible:
\n\
* With one amount, all will receive the amount
\n\
* With one amount, all will receive the amount
\n\
* With many amounts (one per recipient)
"
,
* With many amounts (one per recipient)
"
,
cls
=
cli_
tools
.
MutuallyExclusiveOption
,
cls
=
tools
.
MutuallyExclusiveOption
,
mutually_exclusive
=
[
"
file_path
"
],
mutually_exclusive
=
[
"
file_path
"
],
)
)
@click.option
(
@click.option
(
...
@@ -105,7 +105,7 @@ Sending to many recipients is possible:\n\
...
@@ -105,7 +105,7 @@ Sending to many recipients is possible:\n\
"
-f
"
,
"
-f
"
,
help
=
"
File’s path containing a list of amounts in absolute or
\
help
=
"
File’s path containing a list of amounts in absolute or
\
relative reference and recipients’ pubkeys
"
,
relative reference and recipients’ pubkeys
"
,
cls
=
cli_
tools
.
MutuallyExclusiveOption
,
cls
=
tools
.
MutuallyExclusiveOption
,
mutually_exclusive
=
[
"
recipients
"
,
"
amounts
"
,
"
amountsUD
"
,
"
allsources
"
],
mutually_exclusive
=
[
"
recipients
"
,
"
amounts
"
,
"
amountsUD
"
,
"
allsources
"
],
)
)
@click.option
(
"
--comment
"
,
"
-c
"
,
default
=
""
,
help
=
"
Comment
"
)
@click.option
(
"
--comment
"
,
"
-c
"
,
default
=
""
,
help
=
"
Comment
"
)
...
...
This diff is collapsed.
Click to expand it.
silkaj/tools.py
+
25
−
0
View file @
20e00de3
...
@@ -15,6 +15,9 @@
...
@@ -15,6 +15,9 @@
import
functools
import
functools
import
sys
import
sys
from
typing
import
Any
import
click
from
silkaj.blockchain.tools
import
get_blockchain_parameters
from
silkaj.blockchain.tools
import
get_blockchain_parameters
from
silkaj.constants
import
FAILURE_EXIT_STATUS
,
G1_SYMBOL
,
GTEST_SYMBOL
from
silkaj.constants
import
FAILURE_EXIT_STATUS
,
G1_SYMBOL
,
GTEST_SYMBOL
...
@@ -31,3 +34,25 @@ def get_currency_symbol() -> str:
...
@@ -31,3 +34,25 @@ def get_currency_symbol() -> str:
def
message_exit
(
message
:
str
)
->
None
:
def
message_exit
(
message
:
str
)
->
None
:
print
(
message
)
print
(
message
)
sys
.
exit
(
FAILURE_EXIT_STATUS
)
sys
.
exit
(
FAILURE_EXIT_STATUS
)
# pylint: disable=too-few-public-methods
class
MutuallyExclusiveOption
(
click
.
Option
):
def
__init__
(
self
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
None
:
self
.
mutually_exclusive
=
set
(
kwargs
.
pop
(
"
mutually_exclusive
"
,
[]))
_help
=
kwargs
.
get
(
"
help
"
,
""
)
if
self
.
mutually_exclusive
:
ex_str
=
"
,
"
.
join
(
self
.
mutually_exclusive
)
kwargs
[
"
help
"
]
=
f
"
{
_help
}
NOTE: This argument is mutually exclusive with arguments: [
{
ex_str
}
].
"
super
().
__init__
(
*
args
,
**
kwargs
)
def
handle_parse_result
(
self
,
ctx
:
click
.
Context
,
opts
:
Any
,
args
:
Any
)
->
Any
:
if
self
.
mutually_exclusive
.
intersection
(
opts
)
and
self
.
name
in
opts
:
arguments
=
"
,
"
.
join
(
self
.
mutually_exclusive
)
raise
click
.
UsageError
(
f
"
Usage: `
{
self
.
name
}
` is mutually exclusive with arguments `
{
arguments
}
`.
"
)
return
super
().
handle_parse_result
(
ctx
,
opts
,
args
)
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