Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the functionalities of the command line parameters #1988

Merged
merged 24 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
db00d95
[arcane:launcher,utils] Add a generic help (with option --help or -h)
AlexlHer Feb 4, 2025
64251d4
[arcane:core] Add the symbol replacing process in options
AlexlHer Feb 4, 2025
09281e2
[arcane:core] Add option replacement with command line
AlexlHer Feb 4, 2025
e1b1548
[arcane:impl,launcher] Remove now useless string replacement in Arcan…
AlexlHer Feb 4, 2025
de6e1d9
[arcane:core,tests] Add name and mesh-name replacement for MultiServ…
AlexlHer Feb 5, 2025
aac70e4
[arcane:core,utils,tests] Add ParameterCaseOption class to manage opt…
AlexlHer Feb 11, 2025
0936746
[arcane:core,tests] Add 'optional' attribute in .axl when there are m…
AlexlHer Feb 11, 2025
6a49478
[arcane:core] Add ParameterCaseOption support in CaseOptionExtended
AlexlHer Feb 11, 2025
9a25b72
[arcane:core] Remove multiple String creation
AlexlHer Feb 12, 2025
02b234f
[arcane:utils] Create new structs 'ParameterCaseOptionLine/Part' to …
AlexlHer Feb 12, 2025
a7ffe26
[arcane:utils,tests] Replace old methods in ParameterCaseOption with …
AlexlHer Feb 14, 2025
e00a108
[arcane:utils] Rename ParameterOption classes and methods
AlexlHer Feb 14, 2025
9ab9895
[arcane:utils] Add doc for ParameterOption classes
AlexlHer Feb 14, 2025
67b6f00
[arcane:core,utils] Move ParameterOption classes to internal/Paramet…
AlexlHer Feb 15, 2025
32fd587
[arcane:core] Add CaseOptionException in the CaseOptions 'Multi' parts
AlexlHer Feb 15, 2025
b65e878
[arcane:core,utils,launcher] Update header
AlexlHer Feb 15, 2025
32965be
[arcane:utils] Replace ASSERTS with FATALS for user dependent errors
AlexlHer Feb 17, 2025
45b22b4
[arcane:tests] Add unit tests for ParameterOption classes
AlexlHer Feb 17, 2025
17fa32c
[arcane:utils,tests] Add three tests for the Command Line Replace part
AlexlHer Feb 17, 2025
df9208e
[arcane:tests] Add unit tests for ParameterCaseOption
AlexlHer Feb 17, 2025
5a3223f
[arcane:tests] Add some fail tests for CaseOptions
AlexlHer Feb 17, 2025
d4889f6
[arcane:tests] Remove a unit test in internal part
AlexlHer Feb 17, 2025
0bcf9b6
[arcane:tests] Add a test for the StringVariableReplace::replaceWith…
AlexlHer Feb 17, 2025
7f80370
[arcane:tests] Add a test for CaseOptionExtended
AlexlHer Feb 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions arcane/src/arcane/core/CaseOptionBase.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* CaseOptionBase.cc (C) 2000-2023 */
/* CaseOptionBase.cc (C) 2000-2025 */
/* */
/* Gestion des options du jeu de données. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -54,6 +54,7 @@ class CaseOptionBasePrivate
String m_default_value; //!< Valeur par défaut
Integer m_min_occurs; //!< Nombre minimum d'occurences
Integer m_max_occurs; //!< Nombre maximum d'occurences (-1 == unbounded)
bool m_is_optional;
bool m_is_initialized; //!< \a true si initialisé
bool m_is_override_default; //!< \a true si la valeur par défaut est surchargée
//! Liste des noms d'options par langue.
Expand All @@ -77,6 +78,7 @@ CaseOptionBasePrivate(const CaseOptionBuildInfo& cob)
, m_default_value(m_axl_default_value)
, m_min_occurs(cob.minOccurs())
, m_max_occurs(cob.maxOccurs())
, m_is_optional(cob.isOptional())
, m_is_initialized(false)
, m_is_override_default(false)
{
Expand Down Expand Up @@ -227,6 +229,15 @@ maxOccurs() const
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

bool CaseOptionBase::
isOptional() const
{
return m_p->m_is_optional;
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void CaseOptionBase::
_setTranslatedName()
{
Expand Down Expand Up @@ -349,6 +360,11 @@ _checkMinMaxOccurs(Integer nb_occur)
{
Integer min_occurs = m_p->m_min_occurs;
Integer max_occurs = m_p->m_max_occurs;
bool is_optional = m_p->m_is_optional;

if (nb_occur == 0 && is_optional) {
return;
}

if (nb_occur<min_occurs){
StringBuilder msg = "Bad number of occurences (less than min)";
Expand Down
9 changes: 6 additions & 3 deletions arcane/src/arcane/core/CaseOptionBase.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* CaseOptionBase.h (C) 2000-2023 */
/* CaseOptionBase.h (C) 2000-2025 */
/* */
/* Classe d'une base d'une option du jeu de donnés. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -108,7 +108,10 @@ class ARCANE_CORE_EXPORT CaseOptionBase

//! Nombre maximum d'occurences (pour une option multiple) (-1 == unbounded)
Integer maxOccurs() const;


//! Permet de savoir si une option est optionnelle.
bool isOptional() const;

/*! \brief Met à jour la valeur de l'option à partir d'une fonction.
*
* Si l'option n'est pas liée à une table de marche, ne fait rien.
Expand Down
122 changes: 107 additions & 15 deletions arcane/src/arcane/core/CaseOptionExtended.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* CaseOptionExtended.cc (C) 2000-2023 */
/* CaseOptionExtended.cc (C) 2000-2025 */
/* */
/* Option du jeu de données de type 'Extended'. */
/*---------------------------------------------------------------------------*/
Expand All @@ -15,12 +15,22 @@

#include "arcane/utils/ITraceMng.h"
#include "arcane/utils/FatalErrorException.h"
#include "arcane/utils/ApplicationInfo.h"
#include "arcane/utils/CommandLineArguments.h"
#include "arcane/utils/ParameterList.h"
#include "arcane/utils/ParameterCaseOption.h"
#include "arcane/utils/StringBuilder.h"

#include "arcane/core/IApplication.h"
#include "arcane/core/ICaseMng.h"
#include "arcane/core/CaseOptionError.h"
#include "arcane/core/ICaseDocumentVisitor.h"
#include "arcane/core/XmlNodeList.h"
#include "arcane/core/ICaseOptionList.h"
#include "arcane/core/MeshHandle.h"
#include "arcane/core/ICaseDocument.h"
#include "arcane/core/CaseOptionException.h"
#include "arcane/core/internal/StringVariableReplace.h"

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
Expand All @@ -41,25 +51,107 @@
void CaseOptionMultiExtended::
_search(bool is_phase1)
{
XmlNodeList elem_list = rootElement().children(name());
ITraceMng* tm = traceMng();
const ParameterList& params = caseMng()->application()->applicationInfo().commandLineArguments().parameters();
const ParameterCaseOption pco{ params.getParameterCaseOption(caseDocumentFragment()->language()) };
String full_xpath = String::format("{0}/{1}", rootElement().xpathFullName(), name());

// !!! En XML, on commence par 1 et non 0.
UniqueArray<Integer> option_in_param;

pco.indexesInParam(full_xpath, option_in_param, false);

XmlNodeList elem_list = rootElement().children(name());
Integer size = elem_list.size();
_checkMinMaxOccurs(size);
if (size==0)
bool is_optional = isOptional();

if (size == 0 && option_in_param.empty() && is_optional) {
return;
}

Integer min_occurs = minOccurs();
Integer max_occurs = maxOccurs();

Integer max_in_param = 0;

// On regarde si l'utilisateur n'a pas mis un indice trop élevé pour l'option dans la ligne de commande.
if (!option_in_param.empty()) {
max_in_param = option_in_param[0];
for (Integer index : option_in_param) {
if (index > max_in_param)
max_in_param = index;

Check warning on line 82 in arcane/src/arcane/core/CaseOptionExtended.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/core/CaseOptionExtended.cc#L82

Added line #L82 was not covered by tests
}
if (max_occurs >= 0) {
if (max_in_param > max_occurs) {
StringBuilder msg = "Bad number of occurences in command line (greater than max)";
msg += " index_max_in_param=";
msg += max_in_param;
msg += " max_occur=";
msg += max_occurs;
msg += " option=";
msg += full_xpath;
throw CaseOptionException(A_FUNCINFO, msg.toString(), true);
}
}
}

if (is_phase1){
_allocate(size);
m_values.resize(size);
if (max_occurs >= 0) {
if (size > max_occurs) {
StringBuilder msg = "Bad number of occurences (greater than max)";
msg += " nb_occur=";
msg += size;
msg += " max_occur=";
msg += max_occurs;
msg += " option=";
msg += full_xpath;
throw CaseOptionException(A_FUNCINFO, msg.toString(), true);

Check warning on line 107 in arcane/src/arcane/core/CaseOptionExtended.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/core/CaseOptionExtended.cc#L100-L107

Added lines #L100 - L107 were not covered by tests
}
}

// Il y aura toujours au moins min_occurs options.
// S'il n'y a pas assez l'options dans le jeu de données et dans les paramètres de la
// ligne de commande, on ajoute des services par défaut (si pas de défaut, il y aura un plantage).
Integer final_size = std::max(size, std::max(min_occurs, max_in_param));

if (is_phase1) {
_allocate(final_size);
m_values.resize(final_size);
}
else{
//cerr << "** MULTI SEARCH " << size << endl;
for( Integer i=0; i<size; ++i ){
XmlNode velem = elem_list[i];
// Si l'option n'est pas présente dans le jeu de donnée, on prend
// l'option par défaut.
String str_val = (velem.null()) ? _defaultValue() : velem.value();
else {
// D'abord, on aura les options du jeu de données : comme on ne peut pas définir un indice
// pour les options dans le jeu de données, elles seront forcément au début et seront contigües.
// Puis, s'il manque des options pour atteindre le min_occurs, on ajoute des options par défaut.
// S'il n'y a pas d'option par défaut, il y aura une exception.
// Enfin, l'utilisateur peut avoir ajouté des options à partir de la ligne de commande. On les ajoute alors.
// Si l'utilisateur souhaite modifier des valeurs du jeu de données à partir de la ligne de commande, on
// remplace les options au fur et à mesure de la lecture.
for (Integer i = 0; i < final_size; ++i) {
String str_val;

// Partie paramètres de la ligne de commande.
if (option_in_param.contains(i + 1)) {
str_val = pco.getParameterOrNull(full_xpath, i + 1, false);

Check warning on line 133 in arcane/src/arcane/core/CaseOptionExtended.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/core/CaseOptionExtended.cc#L133

Added line #L133 was not covered by tests
}

// Partie jeu de données.
else if (i < size) {
XmlNode velem = elem_list[i];
if (!velem.null()) {
str_val = velem.value();
}
}

// Valeur par défaut.
if (str_val.null()) {
str_val = _defaultValue();

Check warning on line 146 in arcane/src/arcane/core/CaseOptionExtended.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/core/CaseOptionExtended.cc#L146

Added line #L146 was not covered by tests
}
else {
// Dans un else : Le remplacement de symboles ne s'applique pas pour les valeurs par défault du .axl.
str_val = StringVariableReplace::replaceWithCmdLineArgs(params, str_val, true);
}

// Maintenant, ce plantage concerne aussi le cas où il n'y a pas de valeurs par défaut et qu'il n'y a
// pas assez d'options pour atteindre le min_occurs.
if (str_val.null()) {
CaseOptionError::addOptionNotFoundError(caseDocumentFragment(),A_FUNCINFO,
name(),rootElement());
Expand Down
18 changes: 12 additions & 6 deletions arcane/src/arcane/core/CaseOptionList.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* CaseOptionList.cc (C) 2000-2023 */
/* CaseOptionList.cc (C) 2000-2025 */
/* */
/* Liste d'options de configuration d'un service ou module. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -216,6 +216,9 @@
bool isOptional() const override { return m_is_optional; }
void setOptional(bool v) { m_is_optional = v; }

Integer minOccurs() const override { return m_is_optional ? 0 : 1; }
Integer maxOccurs() const override { return 1; }

Check warning on line 220 in arcane/src/arcane/core/CaseOptionList.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/core/CaseOptionList.cc#L219-L220

Added lines #L219 - L220 were not covered by tests

void setRootElementWithParent(XmlNode parent_element) override
{
_setRootElement(false,parent_element);
Expand Down Expand Up @@ -564,6 +567,8 @@
public:

bool isOptional() const override { return true; }
Integer minOccurs() const override { return m_min_occurs; }
Integer maxOccurs() const override { return m_max_occurs; }
void readChildren(bool is_phase1) override;
void addInvalidChildren(XmlNodeList& nlist) override;
void printChildren(const String& lang,int indent) override;
Expand Down Expand Up @@ -608,10 +613,11 @@

m_root_element_list = m_parent_element.children(rootTagName());
m_case_config_list.clear();
Integer s = m_root_element_list.size();
_checkMinMaxOccurs(s);
if (s!=0)
m_case_option_multi->multiAllocate(m_root_element_list);
// Ces vérifications sont faites dans multiAllocate().
//Integer s = m_root_element_list.size();
//_checkMinMaxOccurs(s);
//if (s!=0)
m_case_option_multi->multiAllocate(m_root_element_list);
// Récupère les options créées lors de l'appel à 'multiAllocate' et
// les ajoute à la liste.
Integer nb_children = m_case_option_multi->nbChildren();
Expand Down
Loading
Loading