mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
feat: impl docs (#4)
The entire public api is covered with documentation in two languages - Russian and English. the library now supports the latest three versions of python - 3.12, 3.13 and 3.14 minor design changes: now, when a Boolean flag is entered, its value is an empty string, not None. tests have been adapted to the supported versions of python, readmi has been redesigned in two languages, German is no longer available.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
from argenta.command import Flags, PredefinedFlags
|
||||
|
||||
# Using predefined flags when creating a command
|
||||
command_flags = Flags(
|
||||
[
|
||||
PredefinedFlags.HELP,
|
||||
PredefinedFlags.SHORT_HELP,
|
||||
PredefinedFlags.INFO,
|
||||
]
|
||||
)
|
||||
|
||||
# Using Network Flags
|
||||
network_flags = Flags(
|
||||
[
|
||||
PredefinedFlags.HOST,
|
||||
PredefinedFlags.PORT,
|
||||
]
|
||||
)
|
||||
|
||||
# Validating the values of predefined flags
|
||||
print(PredefinedFlags.HOST.validate_input_flag_value("192.168.1.1")) # True
|
||||
print(PredefinedFlags.HOST.validate_input_flag_value("invalid")) # False
|
||||
|
||||
print(PredefinedFlags.PORT.validate_input_flag_value("8080")) # True
|
||||
print(PredefinedFlags.PORT.validate_input_flag_value("99999")) # True
|
||||
print(PredefinedFlags.PORT.validate_input_flag_value("abc")) # False
|
||||
|
||||
# Flags without values
|
||||
print(PredefinedFlags.HELP.validate_input_flag_value(None)) # True
|
||||
print(PredefinedFlags.HELP.validate_input_flag_value("something")) # False
|
||||
|
||||
# Checking string representations
|
||||
print(PredefinedFlags.HELP.string_entity) # --help
|
||||
print(PredefinedFlags.SHORT_HELP.string_entity) # -H
|
||||
print(PredefinedFlags.HOST.string_entity) # --host
|
||||
print(PredefinedFlags.SHORT_PORT.string_entity) # -P
|
||||
@@ -0,0 +1,20 @@
|
||||
import re
|
||||
from argenta.command import Flag, PossibleValues
|
||||
|
||||
# Simple flag with any values
|
||||
verbose_flag = Flag(name="verbose")
|
||||
|
||||
# Flag with short prefix
|
||||
short_flag = Flag(name="v", prefix="-")
|
||||
|
||||
# Flag that does not take a value
|
||||
help_flag = Flag(name="help", possible_values=PossibleValues.NEITHER)
|
||||
|
||||
# Flag with list of possible values
|
||||
format_flag = Flag(name="format", possible_values=["json", "xml", "csv"])
|
||||
|
||||
# Flag with regexp for validation input value
|
||||
email_flag = Flag(
|
||||
name="email",
|
||||
possible_values=re.compile(r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"),
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
import re
|
||||
|
||||
from argenta.command.flag.models import Flag, PossibleValues
|
||||
|
||||
# Flag with list of allowed values
|
||||
format_flag = Flag(name="format", possible_values=["json", "xml", "csv"])
|
||||
|
||||
# Value validation
|
||||
print(format_flag.validate_input_flag_value("json")) # True
|
||||
print(format_flag.validate_input_flag_value("pdf")) # False
|
||||
|
||||
# Flag without value
|
||||
help_flag = Flag(name="help", possible_values=PossibleValues.NEITHER)
|
||||
print(help_flag.validate_input_flag_value(None)) # True
|
||||
print(help_flag.validate_input_flag_value("value")) # False
|
||||
|
||||
# Flag with regular expression
|
||||
port_flag = Flag(name="port", possible_values=re.compile(r"^\d{1,5}$"))
|
||||
print(port_flag.validate_input_flag_value("8080")) # True
|
||||
print(port_flag.validate_input_flag_value("abc")) # False
|
||||
@@ -0,0 +1,9 @@
|
||||
from argenta.command import Flag
|
||||
|
||||
help_flag = Flag(name="help")
|
||||
version_flag = Flag(name="V", prefix="-")
|
||||
|
||||
print(help_flag) # --help
|
||||
|
||||
message = f"Use {help_flag} to see help"
|
||||
print(message) # Use --help to see help
|
||||
@@ -0,0 +1,12 @@
|
||||
from argenta.command import Flag
|
||||
|
||||
verbose_flag = Flag(name="verbose", prefix="--")
|
||||
short_flag = Flag(name="v", prefix="-")
|
||||
|
||||
# Debug view
|
||||
print(repr(verbose_flag)) # Flag<prefix=--, name=verbose>
|
||||
print(repr(short_flag)) # Flag<prefix=-, name=v>
|
||||
|
||||
# In an interactive console or debugger
|
||||
# >>> verbose_flag
|
||||
# Flag<prefix=--, name=verbose>
|
||||
@@ -0,0 +1,21 @@
|
||||
from argenta.command import Flag, PossibleValues
|
||||
|
||||
# Creating two flags with the same name and prefix
|
||||
flag1 = Flag(name="verbose", prefix="--")
|
||||
flag2 = Flag(name="verbose", prefix="--")
|
||||
|
||||
# Flag comparison
|
||||
print(flag1 == flag2) # True
|
||||
|
||||
# Flags with different prefixes are not equal
|
||||
flag3 = Flag(name="verbose", prefix="-")
|
||||
print(flag1 == flag3) # False
|
||||
|
||||
# Flags with different names are not equal
|
||||
flag4 = Flag(name="help", prefix="--")
|
||||
print(flag1 == flag4) # False
|
||||
|
||||
# Different possible_values do not affect equality
|
||||
flag5 = Flag(name="verbose", prefix="--", possible_values=PossibleValues.NEITHER)
|
||||
flag6 = Flag(name="verbose", prefix="--", possible_values=["value1", "value2"])
|
||||
print(flag5 == flag6)
|
||||
Reference in New Issue
Block a user