feat: able to lad config_file name from environement variable
This commit is contained in:
parent
82e9e5bc30
commit
1576f105e0
11 changed files with 83 additions and 18 deletions
|
|
@ -5,8 +5,8 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"POT-Creation-Date: 2025-05-12 08:44+0200\n"
|
||||
"PO-Revision-Date: 2025-05-12 08:44+0200\n"
|
||||
"POT-Creation-Date: 2025-05-14 08:22+0200\n"
|
||||
"PO-Revision-Date: 2025-05-14 08:22+0200\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"Language: fr\n"
|
||||
|
|
@ -16,15 +16,15 @@ msgstr ""
|
|||
"Generated-By: pygettext.py 1.5\n"
|
||||
"X-Generator: Poedit 3.5\n"
|
||||
|
||||
#: src/rougail/cli/__main__.py:151
|
||||
#: src/rougail/cli/__main__.py:170
|
||||
msgid "cannot find \"user_data\" module \"{0}\""
|
||||
msgstr "ne peut trouve le module \"user_data\" \"{0}\""
|
||||
|
||||
#: src/rougail/cli/__main__.py:195
|
||||
#: src/rougail/cli/__main__.py:214
|
||||
msgid "cannot find cli file for \"output_name\" module \"{0}\""
|
||||
msgstr "ne peut trouve le fichier cli pour le module \"output_name\" \"{0}\""
|
||||
|
||||
#: src/rougail/cli/__main__.py:221
|
||||
#: src/rougail/cli/__main__.py:240
|
||||
msgid "ERROR: {0}"
|
||||
msgstr "ERREUR : {0}"
|
||||
|
||||
|
|
@ -37,11 +37,15 @@ msgid "Loads command line parameters from a file"
|
|||
msgstr "Charger les paramètres de la ligne de commande depuis un fichier"
|
||||
|
||||
#: src/rougail/cli/config.py:39
|
||||
msgid "Display debug informations"
|
||||
msgid "Displays debug informations"
|
||||
msgstr "Afficher les informations de debug"
|
||||
|
||||
#: src/rougail/cli/config.py:43
|
||||
msgid "Display Rougail version and all componants"
|
||||
msgid "Displays command line option warnings informations"
|
||||
msgstr "Afficher les avertissements de chargement des options de la ligne de commande"
|
||||
|
||||
#: src/rougail/cli/config.py:47
|
||||
msgid "Displays Rougail version and all its components"
|
||||
msgstr "Afficher la version de Rougail et de tous ces composants"
|
||||
|
||||
#~ msgid "do not display debug informations"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"POT-Creation-Date: 2025-05-12 08:44+0200\n"
|
||||
"POT-Creation-Date: 2025-05-14 08:25+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
|
@ -15,15 +15,15 @@ msgstr ""
|
|||
"Generated-By: pygettext.py 1.5\n"
|
||||
|
||||
|
||||
#: src/rougail/cli/__main__.py:151
|
||||
#: src/rougail/cli/__main__.py:170
|
||||
msgid "cannot find \"user_data\" module \"{0}\""
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/cli/__main__.py:195
|
||||
#: src/rougail/cli/__main__.py:214
|
||||
msgid "cannot find cli file for \"output_name\" module \"{0}\""
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/cli/__main__.py:221
|
||||
#: src/rougail/cli/__main__.py:240
|
||||
msgid "ERROR: {0}"
|
||||
msgstr ""
|
||||
|
||||
|
|
@ -36,10 +36,14 @@ msgid "Loads command line parameters from a file"
|
|||
msgstr ""
|
||||
|
||||
#: src/rougail/cli/config.py:39
|
||||
msgid "Display debug informations"
|
||||
msgid "Displays debug informations"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/cli/config.py:43
|
||||
msgid "Display Rougail version and all componants"
|
||||
msgid "Displays command line option warnings informations"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/cli/config.py:47
|
||||
msgid "Displays Rougail version and all its components"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
|
|||
along with Mtools. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import os
|
||||
from warnings import warn
|
||||
from pathlib import Path
|
||||
from sys import exit
|
||||
|
|
@ -41,6 +42,9 @@ except ImportError:
|
|||
from .i18n import _
|
||||
|
||||
|
||||
ENV_PREFIX = "ROUGAILCLI"
|
||||
|
||||
|
||||
def _main(arguments, do_not_print):
|
||||
rougailconfig = get_rougail_config(
|
||||
backward_compatibility=False, add_extra_options=False
|
||||
|
|
@ -57,7 +61,10 @@ def _main(arguments, do_not_print):
|
|||
}
|
||||
fake_user_datas = []
|
||||
if RougailUserDataYaml:
|
||||
config_file = cmd_config.forcepermissive.option("cli.config_file").value.get()
|
||||
cli_config_file_key = f"{ENV_PREFIX}_CLI.CONFIG_FILE"
|
||||
config_file = os.environ.pop(cli_config_file_key, None)
|
||||
if not config_file:
|
||||
config_file = cmd_config.forcepermissive.option("cli.config_file").value.get()
|
||||
if Path(config_file).is_file():
|
||||
fake_rougail_config = {
|
||||
"step.user_data": "yaml",
|
||||
|
|
@ -70,7 +77,7 @@ def _main(arguments, do_not_print):
|
|||
if RougailUserDataEnvironment:
|
||||
fake_rougail_config = {
|
||||
"step.user_data": "environment",
|
||||
"environment.default_environment_name": "ROUGAILCLI",
|
||||
"environment.default_environment_name": ENV_PREFIX,
|
||||
}
|
||||
fake_user_datas.extend(
|
||||
RougailUserDataEnvironment(
|
||||
|
|
@ -89,7 +96,7 @@ def _main(arguments, do_not_print):
|
|||
parser.parse_args(arguments)
|
||||
if user_datas:
|
||||
user_data = UserDatas(cmd_config).user_datas(user_datas, user_datas_type="values")
|
||||
if user_data["warnings"]:
|
||||
if user_data["warnings"] and cmd_config.option("cli.warnings").value.get():
|
||||
for warning in user_data["warnings"]:
|
||||
warn(warning)
|
||||
if user_data["errors"]:
|
||||
|
|
|
|||
|
|
@ -36,11 +36,15 @@ cli:
|
|||
default: .rougailcli.yml
|
||||
|
||||
debug:
|
||||
description: {_('Display debug informations')}
|
||||
description: {_('Displays debug informations')}
|
||||
default: false
|
||||
|
||||
warnings:
|
||||
description: {_('Displays command line option warnings informations')}
|
||||
default: true
|
||||
|
||||
versions:
|
||||
description: {_('Display Rougail version and all componants')}
|
||||
description: {_('Displays Rougail version and all its components')}
|
||||
default: false
|
||||
|
||||
load_config:
|
||||
|
|
|
|||
Binary file not shown.
7
tests/rougailcli_file/.rougailcli.yml
Normal file
7
tests/rougailcli_file/.rougailcli.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
main_dictionaries:
|
||||
- structures
|
||||
step:
|
||||
output: doc
|
||||
doc:
|
||||
output_format: json
|
||||
7
tests/rougailcli_file/alt_rougailcli.yml
Normal file
7
tests/rougailcli_file/alt_rougailcli.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
main_dictionaries:
|
||||
- structures
|
||||
step:
|
||||
output: doc
|
||||
doc:
|
||||
output_format: console
|
||||
1
tests/rougailcli_file/console.txt
Normal file
1
tests/rougailcli_file/console.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
"\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n\u2503\u001b[1m \u001b[0m\u001b[1mVariable \u001b[0m\u001b[1m \u001b[0m\u2503\u001b[1m \u001b[0m\u001b[1mDescription \u001b[0m\u001b[1m \u001b[0m\u2503\n\u2521\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2529\n\u2502 \u001b[1mmy_variable\u001b[0m \u2502 A description. \u2502\n\u2502 \u001b[1;7m string \u001b[0m \u001b[1;7m mandatory \u001b[0m \u2502 \u001b[1mDefault\u001b[0m: my_value \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n"
|
||||
4
tests/rougailcli_file/structures/file.yml
Normal file
4
tests/rougailcli_file/structures/file.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
my_variable: my_value # a description
|
||||
1
tests/rougailcli_file/yaml.txt
Normal file
1
tests/rougailcli_file/yaml.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
"{\n \"my_variable\": {\n \"type\": \"variable\",\n \"default\": \"my_value\",\n \"properties\": [\n {\n \"type\": \"type\",\n \"name\": \"string\"\n },\n {\n \"type\": \"property\",\n \"name\": \"mandatory\"\n }\n ],\n \"paths\": [\n \"my_variable\"\n ],\n \"names\": [\n \"my_variable\"\n ],\n \"descriptions\": [\n \"A description.\"\n ]\n }\n}"
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
from contextlib import chdir
|
||||
from json import dumps, loads
|
||||
|
|
@ -78,3 +79,28 @@ def test_cli_version_user_data_disabled():
|
|||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == (True, data)
|
||||
|
||||
|
||||
def test_cli_rougailcli():
|
||||
with chdir(test_dir / 'rougailcli_file'):
|
||||
ret = main([], do_not_print=True)
|
||||
filename = Path('yaml.txt')
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(dumps(ret[1]))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == (True, data)
|
||||
|
||||
|
||||
def test_cli_alt_rougailcli():
|
||||
with chdir(test_dir / 'rougailcli_file'):
|
||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'alt_rougailcli.yml'
|
||||
ret = main([], do_not_print=True)
|
||||
filename = Path('console.txt')
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(dumps(ret[1]))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == (True, data)
|
||||
|
|
|
|||
Loading…
Reference in a new issue