From ef276cced948f345c48d2bc42b6d87b2e6e71c73 Mon Sep 17 00:00:00 2001 From: Fabien Chouteau Date: Sat, 9 Mar 2024 14:16:05 +0100 Subject: [PATCH] New `alr settings` command to replace `alr config` (#1617) This change is introduced to tackle the confusion between the configuration of the Alire commands and operations, and the configuration of crates. `alr config` is still available and should work as before with the exception of a deprecation warning message. --- doc/configuration.md | 84 ------- doc/getting-started.md | 11 +- doc/settings.md | 84 +++++++ doc/user-changes.md | 11 + src/alire/alire-platforms-current.ads | 4 +- src/alire/alire-toml_index.adb | 4 +- src/alire/alire.adb | 12 +- src/alire/alire.ads | 2 +- src/alr/alr-commands-config.adb | 226 +---------------- src/alr/alr-commands-config.ads | 36 +-- src/alr/alr-commands-settings.adb | 235 ++++++++++++++++++ src/alr/alr-commands-settings.ads | 49 ++++ src/alr/alr-commands-topics-aliases.ads | 4 +- src/alr/alr-commands.adb | 6 +- .../config/shared-deps-profiles/test.py | 2 +- testsuite/drivers/alr.py | 18 +- testsuite/drivers/builds.py | 4 +- testsuite/drivers/driver/docker_nested.py | 4 +- testsuite/drivers/driver/python_script.py | 2 +- testsuite/drivers/helpers.py | 2 +- testsuite/tests/alias/basic/test.py | 2 +- .../tests/build_profile/last_profile/test.py | 8 +- .../misc/failed-auto-update/test.py | 6 +- testsuite/tests/index/auto-update/test.py | 2 +- testsuite/tests/index/branch-mismatch/test.py | 2 +- .../tests/index/local-index-not-found/test.py | 2 +- .../tests/index/old-compat-version/test.py | 2 +- .../tests/init/interactive-inputs/test.py | 2 +- .../tests/init/user-input-validation/test.py | 6 +- .../tests/install/default-location/test.py | 2 +- testsuite/tests/misc/git-ungit/test.py | 2 +- .../publish/submit-request-cancel/test.py | 4 +- .../tests/{config => settings}/basics/test.py | 42 ++-- .../{config => settings}/basics/test.yaml | 0 .../cache-relocation/test.py | 12 +- .../cache-relocation/test.yaml | 0 .../community-disable/test.py | 0 .../community-disable/test.yaml | 0 .../distro-disable/test.py | 2 +- .../distro-disable/test.yaml | 0 .../distro-override/test.py | 4 +- .../distro-override/test.yaml | 0 .../early-loading/test.py | 6 +- .../early-loading/test.yaml | 0 .../my_index/he/hello/hello-1.0.0.toml | 0 .../my_index/he/hello/hello-1.0.1.toml | 0 .../my_index/index.toml | 0 .../my_index/li/libhello/libhello-1.0.0.toml | 0 .../missing-config-default/test.py | 0 .../missing-config-default/test.yaml | 0 .../relative_config_path/test.py | 2 +- .../relative_config_path/test.yaml | 0 .../{config => settings}/shared-deps/test.py | 0 .../shared-deps/test.yaml | 0 .../tests/solver/compiler-selected/test.py | 2 +- .../tests/toolchain/select-defaults/test.py | 2 +- .../toolchain/select-while-missing/test.py | 2 +- testsuite/tests/workflows/edit/test.py | 6 +- 58 files changed, 496 insertions(+), 424 deletions(-) delete mode 100644 doc/configuration.md create mode 100644 doc/settings.md create mode 100644 src/alr/alr-commands-settings.adb create mode 100644 src/alr/alr-commands-settings.ads rename testsuite/tests/{config => settings}/basics/test.py (68%) rename testsuite/tests/{config => settings}/basics/test.yaml (100%) rename testsuite/tests/{config => settings}/cache-relocation/test.py (65%) rename testsuite/tests/{config => settings}/cache-relocation/test.yaml (100%) rename testsuite/tests/{config => settings}/community-disable/test.py (100%) rename testsuite/tests/{config => settings}/community-disable/test.yaml (100%) rename testsuite/tests/{config => settings}/distro-disable/test.py (88%) rename testsuite/tests/{config => settings}/distro-disable/test.yaml (100%) rename testsuite/tests/{config => settings}/distro-override/test.py (91%) rename testsuite/tests/{config => settings}/distro-override/test.yaml (100%) rename testsuite/tests/{config => settings}/early-loading/test.py (77%) rename testsuite/tests/{config => settings}/early-loading/test.yaml (100%) rename testsuite/tests/{config => settings}/missing-config-default/my_index/he/hello/hello-1.0.0.toml (100%) rename testsuite/tests/{config => settings}/missing-config-default/my_index/he/hello/hello-1.0.1.toml (100%) rename testsuite/tests/{config => settings}/missing-config-default/my_index/index.toml (100%) rename testsuite/tests/{config => settings}/missing-config-default/my_index/li/libhello/libhello-1.0.0.toml (100%) rename testsuite/tests/{config => settings}/missing-config-default/test.py (100%) rename testsuite/tests/{config => settings}/missing-config-default/test.yaml (100%) rename testsuite/tests/{config => settings}/relative_config_path/test.py (88%) rename testsuite/tests/{config => settings}/relative_config_path/test.yaml (100%) rename testsuite/tests/{config => settings}/shared-deps/test.py (100%) rename testsuite/tests/{config => settings}/shared-deps/test.yaml (100%) diff --git a/doc/configuration.md b/doc/configuration.md deleted file mode 100644 index e7f6ac93..00000000 --- a/doc/configuration.md +++ /dev/null @@ -1,84 +0,0 @@ -# Configuration - -`alr` provides a generic mechanism to `list`, `get`, `set` or -`unset` configuration options, either in a local or global context. - - Option names (keys) can use lowercase and uppercase alphanumeric characters - from the Latin alphabet. Underscores and dashes can also be used except as - the first or last character. Dot '.' is used to specify sub-categories, e.g. - 'user.name' or 'user.email'. - - Option values can be integers, floats, Booleans (true or false), or strings. The - type detection is automatic, e.g. 10 is integer, 10.1 is float, true is - Boolean. You can force a value to be a string by using double-quotes, e.g. - "10.1" or "true". Extra type checking is used for built-in options (see below). - - Specific config options: - - - `--list` List configuration options - - `--show-origin` Show origin of configuration values in `--list` - - `--get` Print value of a configuration option - - `--set` Set a configuration option - - `--unset` Unset a configuration option - - `--global` Set and Unset global configuration instead of the local one - - `--builtins-doc` Print Markdown list of built-in configuration options - - Examples: - - - `alr config --global --set my_option option_value` - - Will set a configuration option with the key `my_option` and the string - value `option_value` in the global configuration file. - - - `alr config --get my_option` - - Will print the value configuration option `my_option` if it is defined, - otherwise the command fails. - - -## Custom configuration options - -The `alr config` command allows you to set and get any combination of -configuration option `key` and `value`. You can use this feature to store your -own project related configuration, or implement tools that integrate in an -`Alire` context. However, be careful when naming custom configuration options -because `Alire` may use the same `key` in the future. We recommend using a -distinctive sub-category name, for instance: `my_project.my_config_option`. - -## Built-in configuration options - -The options used by `Alire` are pre-defined and documented. We call these -options `built-ins`. - -A built-in option has a pre-defined type that is checked when setting or -loading a configuration file. For instance: - - - `alr config --global --set user.email "This is not an email address"` - -will fail because the value tentatively assigned to `user.email` is not an -email address. - -The built-ins also have a short description to document their type and usage. - -## Built-ins list - -You can get the list of options recognized by `alr` with `alr help config`, -including their default values and a short explanation of their effects. - -## Relocating your configuration - -By default, `alr` stores its global configuration at `/.config/alire`. You can use any other location by setting in the -environment the variable `ALR_CONFIG=`, or by -using the global `-c` switch: `alr -c `. - -Using a pristine default configuration can be useful to isolate the source of -errors by ensuring that a misconfiguration is not at play. - -## Inspecting your configuration - -These commands may help you in identifying Alire configuration and environment: -- `alr config --list` will show all configuration options in effect. -- `alr version` will print many relevant bits of information about the current - `alr` environment. -- `alr --version` will just print the version number and exit. \ No newline at end of file diff --git a/doc/getting-started.md b/doc/getting-started.md index b9a3b831..3044bdc6 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -34,8 +34,8 @@ libraries required by some projects in the Alire index, allowing you to build more projects out of the box. `msys2` will not be installed -- when running `alr config`, to allow uninterrupted configuration, and configuration - of `msys2` location (see `alr help config`), or +- when running `alr settings`, to allow uninterrupted configuration, and setting + of `msys2` location (see `alr help settings`), or - when you already have a msys2 installation in your PATH (more precisely, if `pacman` is found in your PATH.) - In this case, `alr` will reuse your existing installation. @@ -292,10 +292,9 @@ Subprocess output is shown by default (you can silence it, and anything else not an error) with `-q`, which enables quiet mode. Any subprocess that exist abnormally will be reported, including its invocation arguments. -If you suspect your configuration may be the source of some problem, please -check our section on [Configuration](configuration), and in particular how -to use a [default pristine -configuration](configuration#Relocating-your-configuration) +If you suspect your settings may be the source of some problem, please check +our section on [Settings](setting), and in particular how to use a [default +pristine settings](settings#Relocating-your-settings) ## Running tests diff --git a/doc/settings.md b/doc/settings.md new file mode 100644 index 00000000..26295053 --- /dev/null +++ b/doc/settings.md @@ -0,0 +1,84 @@ +# Settings + +`alr` provides a generic mechanism to `list`, `get`, `set` or +`unset` settings options, either in a local or global context. + + Option names (keys) can use lowercase and uppercase alphanumeric characters + from the Latin alphabet. Underscores and dashes can also be used except as + the first or last character. Dot '.' is used to specify sub-categories, e.g. + 'user.name' or 'user.email'. + + Option values can be integers, floats, Booleans (true or false), or strings. The + type detection is automatic, e.g. 10 is integer, 10.1 is float, true is + Boolean. You can force a value to be a string by using double-quotes, e.g. + "10.1" or "true". Extra type checking is used for built-in options (see below). + + Specific settings options: + + - `--list` List settings options + - `--show-origin` Show origin of settings values in `--list` + - `--get` Print value of a setting option + - `--set` Set a setting option + - `--unset` Unset a setting option + - `--global `Set and Unset global settings instead of the local one + - `--builtins-doc` Print Markdown list of built-in settings + + Examples: + + - `alr settings --global --set my_option option_value` + + Will set a setting option with the key `my_option` and the string + value `option_value` in the global settings file. + + - `alr settings --get my_option` + + Will print the value setting option `my_option` if it is defined, + otherwise the command fails. + + +## Custom settings options + +The `alr settings` command allows you to set and get any combination of option +`key` and `value`. You can use this feature to store your own project related +settings, or implement tools that integrate in an `Alire` context. However, be +careful when naming custom settings options because `Alire` may use the same +`key` in the future. We recommend using a distinctive sub-category name, for +instance: `my_project.my_option`. + +## Built-in settings options + +The options used by `Alire` are pre-defined and documented. We call these +options `built-ins`. + +A built-in option has a pre-defined type that is checked when setting or +loading. For instance: + + - `alr settings --global --set user.email "This is not an email address"` + +will fail because the value tentatively assigned to `user.email` is not an +email address. + +The built-ins also have a short description to document their type and usage. + +## Built-ins list + +You can get the list of options recognized by `alr` with `alr help settings`, +including their default values and a short explanation of their effects. + +## Relocating your settings + +By default, `alr` stores its global settings at `/.config/alire`. +You can use any other location by setting in the environment the variable +`ALR_CONFIG=`, or by using the global `-c` +switch: `alr -c `. + +Using pristine default settings can be useful to isolate the source of errors +by ensuring that a misconfiguration is not at play. + +## Inspecting your settings + +These commands may help you in identifying Alire settings and environment: +- `alr settings --list` will show all settings options in effect. +- `alr version` will print many relevant bits of information about the current + `alr` environment. +- `alr --version` will just print the version number and exit. diff --git a/doc/user-changes.md b/doc/user-changes.md index de4f4900..4e83940f 100644 --- a/doc/user-changes.md +++ b/doc/user-changes.md @@ -6,6 +6,17 @@ stay on top of `alr` new features. ## Release `2.0-dev` +### + +PR [1617](https://github.com/alire-project/alire/pull/1617) + +The `alr settings` command replaces the `alr config` command. This change is +introduced to tackle the confusion between the configuration of the Alire +commands and operations, and the configuration of crates. + +`alr config` is still available and should work as before with the exception of +a deprecation warning message. + ### Deprecation of `toolchain --install/--uninstall/--install-dir` PR [#1614](https://github.com/alire-project/alire/pull/1614) diff --git a/src/alire/alire-platforms-current.ads b/src/alire/alire-platforms-current.ads index 1327c369..913b311a 100644 --- a/src/alire/alire-platforms-current.ads +++ b/src/alire/alire-platforms-current.ads @@ -40,8 +40,8 @@ package Alire.Platforms.Current is procedure Initialize; -- Do any initialization that is necessary for this platform. This is - -- called as soon as we know the user is not running `alr config`, as we - -- want to allow the opportunity to configure things without triggering + -- called as soon as we know the user is not running `alr settings`, as + -- we want to allow the opportunity to configure things without triggering -- this initialization. -------------------------------- diff --git a/src/alire/alire-toml_index.adb b/src/alire/alire-toml_index.adb index 969b19fd..54de246b 100644 --- a/src/alire/alire-toml_index.adb +++ b/src/alire/alire-toml_index.adb @@ -130,7 +130,7 @@ package body Alire.TOML_Index is & TTY.Emph (Alire.Index.Branch_Kind) & "' but your community index branch is '" & TTY.Emph (Local) & "'", - Disable_Config => Config.Builtins.Warning_Old_Index.Key); + Disable_Setting => Config.Builtins.Warning_Old_Index.Key); Suggest_Update := True; end if; end Compare_Branches; @@ -189,7 +189,7 @@ package body Alire.TOML_Index is & "' version (" & Loading_Index_Version.Image & ") is older than the newest supported by alr (" & Alire.Index.Version.Image & ")", - Disable_Config => + Disable_Setting => Config.Builtins.Warning_Old_Index.Key); Suggest_Update := True; elsif not Alire.Index.Valid_Versions.Contains (Loading_Index_Version) diff --git a/src/alire/alire.adb b/src/alire/alire.adb index c205b615..88857118 100644 --- a/src/alire/alire.adb +++ b/src/alire/alire.adb @@ -117,9 +117,9 @@ package body Alire is -- Put_Warning -- ----------------- - procedure Put_Warning (Text : String; - Level : Trace.Levels := Warning; - Disable_Config : String := "") + procedure Put_Warning (Text : String; + Level : Trace.Levels := Warning; + Disable_Setting : String := "") is Prefix : constant String := (if Level = Warning @@ -128,10 +128,10 @@ package body Alire is "Warning: ")); begin Trace.Log (Prefix & Text, Level); - if Disable_Config /= "" then + if Disable_Setting /= "" then Trace.Log (Prefix - & "You can disable this warning with configuration key '" - & TTY.Emph (Disable_Config) & "'", + & "You can disable this warning with settings key '" + & TTY.Emph (Disable_Setting) & "'", Level); end if; end Put_Warning; diff --git a/src/alire/alire.ads b/src/alire/alire.ads index 85714196..2bccc801 100644 --- a/src/alire/alire.ads +++ b/src/alire/alire.ads @@ -287,7 +287,7 @@ package Alire with Preelaborate is procedure Put_Warning (Text : String; Level : Trace.Levels := Warning; - Disable_Config : String := ""); + Disable_Setting : String := ""); -- Prepend Text with a yellow "⚠", or "Warning: " if no color/tty. If -- Disable_setting /= "", append a line informing about how to disable -- this warning. diff --git a/src/alr/alr-commands-config.adb b/src/alr/alr-commands-config.adb index ec395ab1..c2a20253 100644 --- a/src/alr/alr-commands-config.adb +++ b/src/alr/alr-commands-config.adb @@ -1,9 +1,4 @@ -with Alire.Config; -with Alire.Config.Edit; -with Alire.Root; - -with CLIC.Config.Info; -with CLIC.Config.Edit; +with Alire.Warnings; package body Alr.Commands.Config is @@ -15,221 +10,12 @@ package body Alr.Commands.Config is procedure Execute (Cmd : in out Command; Args : AAA.Strings.Vector) is - Enabled : Natural := 0; - - Lvl : constant Alire.Config.Level := (if Cmd.Global - then Alire.Config.Global - else Alire.Config.Local); begin - - -- Check no multi-action - Enabled := Enabled + (if Cmd.List then 1 else 0); - Enabled := Enabled + (if Cmd.Get then 1 else 0); - Enabled := Enabled + (if Cmd.Set then 1 else 0); - Enabled := Enabled + (if Cmd.Unset then 1 else 0); - Enabled := Enabled + (if Cmd.Builtins_Doc then 1 else 0); - - if Enabled > 1 then - Reportaise_Wrong_Arguments ("Specify at most one subcommand"); - end if; - - if Enabled = 0 then - -- The default command is --list - Cmd.List := True; - end if; - - if Cmd.Show_Origin and then not Cmd.List then - Reportaise_Wrong_Arguments - ("--show-origin only valid with --list"); - end if; - - if Cmd.Builtins_Doc then - Alire.Config.Edit.Print_Builtins_Doc; - return; - end if; - - if not Cmd.Global and then not Alire.Root.Current.Is_Valid then - Reportaise_Command_Failed - ("Not in an Alire project directory." & - " Use --global to edit the global configuration."); - end if; - - if Cmd.List then - case Args.Count is - when 0 => - Trace.Always - (CLIC.Config.Info.List - (Alire.Config.DB.all, - Filter => ".*", - Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF)); - when 1 => - Trace.Always - (CLIC.Config.Info.List - (Alire.Config.DB.all, - Filter => Args.First_Element, - Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF)); - when others => - Reportaise_Wrong_Arguments - ("List expects at most one argument"); - end case; - - elsif Cmd.Get then - if Args.Count /= 1 then - Reportaise_Wrong_Arguments ("Unset expects one argument"); - end if; - - if not CLIC.Config.Is_Valid_Config_Key (Args.First_Element) then - Reportaise_Wrong_Arguments ("Invalid configuration key '" & - Args.First_Element & "'"); - end if; - - if Alire.Config.DB.Defined (Args.First_Element) then - Trace.Always (Alire.Config.DB.Get_As_String (Args.First_Element)); - else - Reportaise_Command_Failed ("Configuration key '" & - Args.First_Element & - "' is not defined"); - end if; - elsif Cmd.Set then - if Args.Count /= 2 then - Reportaise_Wrong_Arguments ("Set expects two arguments"); - end if; - - declare - Key : constant String := Args.Element (1); - Val : constant String := Args.Element (2); - begin - - if not CLIC.Config.Is_Valid_Config_Key (Key) then - Reportaise_Wrong_Arguments ("Invalid configuration key '" & - Key & "'"); - end if; - - -- Check explicitly for booleans to store the proper TOML type - -- regardless of the capitalization used by the user. - if Is_Boolean (Val) then - Alire.Config.Edit.Set_Boolean - (Lvl, - Key, Boolean'Value (Val), - Check => Alire.Config.Edit.Valid_Builtin'Access); - else - Alire.Config.Edit.Set - (Lvl, - Key, Val, - Check => Alire.Config.Edit.Valid_Builtin'Access); - end if; - end; - - elsif Cmd.Unset then - if Args.Count /= 1 then - Reportaise_Wrong_Arguments ("Unset expects one argument"); - end if; - - declare - Key : constant String := Args.Element (1); - begin - if not CLIC.Config.Is_Valid_Config_Key (Key) then - Reportaise_Wrong_Arguments ("Invalid configuration key '" & - Key & "'"); - end if; - - if not CLIC.Config.Edit.Unset - (Alire.Config.Edit.Filepath (Lvl), Key) - then - Reportaise_Command_Failed ("Cannot unset config key"); - end if; - end; - end if; + Alire.Warnings.Warn_Once ("`alr " & Command_Name & "` is " & + CLIC.TTY.Error ("deprecated") & ". " & + "Please use `alr " & Settings.Command_Name & + "` instead."); + Parent (Cmd).Execute (Args); end Execute; - ---------------------- - -- Long_Description -- - ---------------------- - - overriding - function Long_Description (Cmd : Command) - return AAA.Strings.Vector is - (AAA.Strings.Empty_Vector - .Append ("Provides a command line interface to the Alire configuration" & - " option files.") - .New_Line - .Append ("Option names (keys) can use lowercase and uppercase" & - " alphanumeric characters") - .Append ("from the Latin alphabet. Underscores and dashes can also be" & - " used except as") - .Append ("first or last character. Dot '.' is used to specify" & - " sub-categories, e.g.") - .Append ("'user.name' or 'user.email'.") - .New_Line - - .Append ("Option values can be integers, float, Boolean (true or" & - " false) or strings. The") - .Append ("type detection is automatic, e.g. 10 is integer, 10.1 is" & - " float, true is") - .Append ("Boolean. You can force a value to be set a string by using" & - " double-quotes, e.g.") - .Append ("""10.1"" or ""true"". Extra type checking is used for" & - " built-in options (see below).") - .New_Line - .Append ("Built-in configuration options:") - .New_Line - .Append (Alire.Config.Edit.Builtins_Info)); - - -------------------- - -- Setup_Switches -- - -------------------- - - overriding - procedure Setup_Switches - (Cmd : in out Command; - Config : in out CLIC.Subcommand.Switches_Configuration) - is - use CLIC.Subcommand; - begin - Define_Switch - (Config => Config, - Output => Cmd.List'Access, - Long_Switch => "--list", - Help => "List configuration options"); - - Define_Switch - (Config => Config, - Output => Cmd.Show_Origin'Access, - Long_Switch => "--show-origin", - Help => "Show origin of configuration values in --list"); - - Define_Switch - (Config => Config, - Output => Cmd.Get'Access, - Long_Switch => "--get", - Help => "Print value of a configuration option"); - - Define_Switch - (Config => Config, - Output => Cmd.Set'Access, - Long_Switch => "--set", - Help => "Set a configuration option"); - - Define_Switch - (Config => Config, - Output => Cmd.Unset'Access, - Long_Switch => "--unset", - Help => "Unset a configuration option"); - - Define_Switch - (Config => Config, - Output => Cmd.Global'Access, - Long_Switch => "--global", - Help => "Set and Unset global configuration instead" & - " of the local one"); - - Define_Switch - (Config => Config, - Output => Cmd.Builtins_Doc'Access, - Long_Switch => "--builtins-doc", - Help => - "Print Markdown list of built-in configuration options"); - - end Setup_Switches; - end Alr.Commands.Config; diff --git a/src/alr/alr-commands-config.ads b/src/alr/alr-commands-config.ads index 32d3101c..9ebbb83b 100644 --- a/src/alr/alr-commands-config.ads +++ b/src/alr/alr-commands-config.ads @@ -1,8 +1,10 @@ with AAA.Strings; +with Alr.Commands.Settings; package Alr.Commands.Config is - type Command is new Commands.Command with private; + subtype Parent is Alr.Commands.Settings.Command; + type Command is new Parent with private; Command_Name : constant String := "config"; @@ -15,35 +17,21 @@ package Alr.Commands.Config is Args : AAA.Strings.Vector); overriding - function Long_Description (Cmd : Command) - return AAA.Strings.Vector; - - overriding - procedure Setup_Switches - (Cmd : in out Command; - Config : in out CLIC.Subcommand.Switches_Configuration); + function Short_Description (Cmd : Command) return String + is (CLIC.TTY.Error ("Deprecated command") & ". " & + "Please use `alr " & Settings.Command_Name & "` instead."); overriding - function Short_Description (Cmd : Command) return String - is ("List, Get, Set or Unset configuration options"); + function Long_Description (Cmd : Command) + return AAA.Strings.Vector + is (AAA.Strings.Empty_Vector); overriding - function Usage_Custom_Parameters (Cmd : Command) return String is - ("[--list] [--show-origin] [key_regex] |" & - " --get |" & - " --set |" & - " --unset "); + function Usage_Custom_Parameters (Cmd : Command) return String + is (""); private - type Command is new Commands.Command with record - Show_Origin : aliased Boolean := False; - List : aliased Boolean := False; - Get : aliased Boolean := False; - Set : aliased Boolean := False; - Unset : aliased Boolean := False; - Global : aliased Boolean := False; - Builtins_Doc : aliased Boolean := False; - end record; + type Command is new Parent with null record; end Alr.Commands.Config; diff --git a/src/alr/alr-commands-settings.adb b/src/alr/alr-commands-settings.adb new file mode 100644 index 00000000..932bd802 --- /dev/null +++ b/src/alr/alr-commands-settings.adb @@ -0,0 +1,235 @@ +with Alire.Config; +with Alire.Config.Edit; +with Alire.Root; + +with CLIC.Config.Info; +with CLIC.Config.Edit; + +package body Alr.Commands.Settings is + + ------------- + -- Execute -- + ------------- + + overriding + procedure Execute (Cmd : in out Command; + Args : AAA.Strings.Vector) + is + Enabled : Natural := 0; + + Lvl : constant Alire.Config.Level := (if Cmd.Global + then Alire.Config.Global + else Alire.Config.Local); + begin + + -- Check no multi-action + Enabled := Enabled + (if Cmd.List then 1 else 0); + Enabled := Enabled + (if Cmd.Get then 1 else 0); + Enabled := Enabled + (if Cmd.Set then 1 else 0); + Enabled := Enabled + (if Cmd.Unset then 1 else 0); + Enabled := Enabled + (if Cmd.Builtins_Doc then 1 else 0); + + if Enabled > 1 then + Reportaise_Wrong_Arguments ("Specify at most one subcommand"); + end if; + + if Enabled = 0 then + -- The default command is --list + Cmd.List := True; + end if; + + if Cmd.Show_Origin and then not Cmd.List then + Reportaise_Wrong_Arguments + ("--show-origin only valid with --list"); + end if; + + if Cmd.Builtins_Doc then + Alire.Config.Edit.Print_Builtins_Doc; + return; + end if; + + if not Cmd.Global and then not Alire.Root.Current.Is_Valid then + Reportaise_Command_Failed + ("Not in an Alire project directory." & + " Use --global to edit the global settings."); + end if; + + if Cmd.List then + case Args.Count is + when 0 => + Trace.Always + (CLIC.Config.Info.List + (Alire.Config.DB.all, + Filter => ".*", + Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF)); + when 1 => + Trace.Always + (CLIC.Config.Info.List + (Alire.Config.DB.all, + Filter => Args.First_Element, + Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF)); + when others => + Reportaise_Wrong_Arguments + ("List expects at most one argument"); + end case; + + elsif Cmd.Get then + if Args.Count /= 1 then + Reportaise_Wrong_Arguments ("Unset expects one argument"); + end if; + + if not CLIC.Config.Is_Valid_Config_Key (Args.First_Element) then + Reportaise_Wrong_Arguments ("Invalid setting key '" & + Args.First_Element & "'"); + end if; + + if Alire.Config.DB.Defined (Args.First_Element) then + Trace.Always (Alire.Config.DB.Get_As_String (Args.First_Element)); + else + Reportaise_Command_Failed ("Setting key '" & + Args.First_Element & + "' is not defined"); + end if; + elsif Cmd.Set then + if Args.Count /= 2 then + Reportaise_Wrong_Arguments ("Set expects two arguments"); + end if; + + declare + Key : constant String := Args.Element (1); + Val : constant String := Args.Element (2); + begin + + if not CLIC.Config.Is_Valid_Config_Key (Key) then + Reportaise_Wrong_Arguments ("Invalid setting key '" & + Key & "'"); + end if; + + -- Check explicitly for booleans to store the proper TOML type + -- regardless of the capitalization used by the user. + if Is_Boolean (Val) then + Alire.Config.Edit.Set_Boolean + (Lvl, + Key, Boolean'Value (Val), + Check => Alire.Config.Edit.Valid_Builtin'Access); + else + Alire.Config.Edit.Set + (Lvl, + Key, Val, + Check => Alire.Config.Edit.Valid_Builtin'Access); + end if; + end; + + elsif Cmd.Unset then + if Args.Count /= 1 then + Reportaise_Wrong_Arguments ("Unset expects one argument"); + end if; + + declare + Key : constant String := Args.Element (1); + begin + if not CLIC.Config.Is_Valid_Config_Key (Key) then + Reportaise_Wrong_Arguments ("Invalid setting key '" & + Key & "'"); + end if; + + if not CLIC.Config.Edit.Unset + (Alire.Config.Edit.Filepath (Lvl), Key) + then + Reportaise_Command_Failed ("Cannot unset setting key"); + end if; + end; + end if; + end Execute; + + ---------------------- + -- Long_Description -- + ---------------------- + + overriding + function Long_Description (Cmd : Command) + return AAA.Strings.Vector is + (AAA.Strings.Empty_Vector + .Append ("Provides a command line interface to the Alire settings" & + " files.") + .New_Line + .Append ("Settings names (keys) can use lowercase and uppercase" & + " alphanumeric characters") + .Append ("from the Latin alphabet. Underscores and dashes can also be" & + " used except as") + .Append ("first or last character. Dot '.' is used to specify" & + " sub-categories, e.g.") + .Append ("'user.name' or 'user.email'.") + .New_Line + + .Append ("Option values can be integers, float, Boolean (true or" & + " false) or strings. The") + .Append ("type detection is automatic, e.g. 10 is integer, 10.1 is" & + " float, true is") + .Append ("Boolean. You can force a value to be set a string by using" & + " double-quotes, e.g.") + .Append ("""10.1"" or ""true"". Extra type checking is used for" & + " built-in options (see below).") + .New_Line + .Append ("Built-in settings:") + .New_Line + .Append (Alire.Config.Edit.Builtins_Info)); + + -------------------- + -- Setup_Switches -- + -------------------- + + overriding + procedure Setup_Switches + (Cmd : in out Command; + Config : in out CLIC.Subcommand.Switches_Configuration) + is + use CLIC.Subcommand; + begin + Define_Switch + (Config => Config, + Output => Cmd.List'Access, + Long_Switch => "--list", + Help => "List settings options"); + + Define_Switch + (Config => Config, + Output => Cmd.Show_Origin'Access, + Long_Switch => "--show-origin", + Help => "Show origin of settings values in --list"); + + Define_Switch + (Config => Config, + Output => Cmd.Get'Access, + Long_Switch => "--get", + Help => "Print value of a setting option"); + + Define_Switch + (Config => Config, + Output => Cmd.Set'Access, + Long_Switch => "--set", + Help => "Set a setting option"); + + Define_Switch + (Config => Config, + Output => Cmd.Unset'Access, + Long_Switch => "--unset", + Help => "Unset a setting option"); + + Define_Switch + (Config => Config, + Output => Cmd.Global'Access, + Long_Switch => "--global", + Help => "Set and Unset global settings instead" & + " of the local one"); + + Define_Switch + (Config => Config, + Output => Cmd.Builtins_Doc'Access, + Long_Switch => "--builtins-doc", + Help => + "Print Markdown list of built-in settings"); + + end Setup_Switches; + +end Alr.Commands.Settings; diff --git a/src/alr/alr-commands-settings.ads b/src/alr/alr-commands-settings.ads new file mode 100644 index 00000000..b42a7e19 --- /dev/null +++ b/src/alr/alr-commands-settings.ads @@ -0,0 +1,49 @@ +with AAA.Strings; + +package Alr.Commands.Settings is + + type Command is new Commands.Command with private; + + Command_Name : constant String := "settings"; + + overriding + function Name (Cmd : Command) return CLIC.Subcommand.Identifier + is (Command_Name); + + overriding + procedure Execute (Cmd : in out Command; + Args : AAA.Strings.Vector); + + overriding + function Long_Description (Cmd : Command) + return AAA.Strings.Vector; + + overriding + procedure Setup_Switches + (Cmd : in out Command; + Config : in out CLIC.Subcommand.Switches_Configuration); + + overriding + function Short_Description (Cmd : Command) return String + is ("List, Get, Set or Unset Alire settings options"); + + overriding + function Usage_Custom_Parameters (Cmd : Command) return String is + ("[--list] [--show-origin] [key_regex] |" & + " --get |" & + " --set |" & + " --unset "); + +private + + type Command is new Commands.Command with record + Show_Origin : aliased Boolean := False; + List : aliased Boolean := False; + Get : aliased Boolean := False; + Set : aliased Boolean := False; + Unset : aliased Boolean := False; + Global : aliased Boolean := False; + Builtins_Doc : aliased Boolean := False; + end record; + +end Alr.Commands.Settings; diff --git a/src/alr/alr-commands-topics-aliases.ads b/src/alr/alr-commands-topics-aliases.ads index a572b944..e9c48175 100644 --- a/src/alr/alr-commands-topics-aliases.ads +++ b/src/alr/alr-commands-topics-aliases.ads @@ -18,10 +18,10 @@ package Alr.Commands.Topics.Aliases is function Content (This : Topic) return AAA.Strings.Vector is (AAA.Strings.Empty_Vector .Append ("Command aliases can be defined in local or global ") - .Append ("configuration.") + .Append ("settings.") .New_Line .Append ("For example the following command:") - .Append ("""$ alr config --set --global alias.graph 'show --graph'""") + .Append ("""$ alr settings --set --global alias.graph 'show --graph'""") .Append ("Defines a global alias for the 'show' command with a ") .Append ("'--graph' switch.") .New_Line diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index 5ad5b79a..96a77f62 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -36,6 +36,7 @@ with Alr.Commands.Printenv; with Alr.Commands.Publish; with Alr.Commands.Run; with Alr.Commands.Search; +with Alr.Commands.Settings; with Alr.Commands.Show; with Alr.Commands.Test; with Alr.Commands.Toolchain; @@ -523,12 +524,14 @@ package body Alr.Commands is begin if Sub_Cmd.What_Command /= Config.Command_Name + and then + Sub_Cmd.What_Command /= Settings.Command_Name then Alire.Platforms.Current.Initialize; Trace.Debug ("Platform-specific initialization done."); else Trace.Debug - ("Platform-specific initialization skipped (alr config)."); + ("Platform-specific initialization skipped (alr settings)."); end if; exception when Sub_Cmd.Error_No_Command => @@ -661,6 +664,7 @@ begin -- Commands -- Sub_Cmd.Register ("General", new Sub_Cmd.Builtin_Help); + Sub_Cmd.Register ("General", new Settings.Command); Sub_Cmd.Register ("General", new Config.Command); Sub_Cmd.Register ("General", new Install.Command); Sub_Cmd.Register ("General", new Toolchain.Command); diff --git a/testsuite/deprecated/config/shared-deps-profiles/test.py b/testsuite/deprecated/config/shared-deps-profiles/test.py index fde5a9aa..b742050f 100644 --- a/testsuite/deprecated/config/shared-deps-profiles/test.py +++ b/testsuite/deprecated/config/shared-deps-profiles/test.py @@ -11,7 +11,7 @@ deps_dir = "deps" # Enable sharing of dependencies os.mkdir(deps_dir) -run_alr("config", "--global", "--set", "dependencies.dir", +run_alr("settings", "--global", "--set", "dependencies.dir", os.path.abspath(deps_dir)) # Create a crate with a dependency diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index b01d1859..809e968f 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -49,18 +49,18 @@ def prepare_env(config_dir, env): if platform.system() == "Windows": # Disable msys inadvertent installation - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "msys2.do_not_install", "true") # And configure the one set up in the environment so it is used by # tests that need it. - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "msys2.install_dir", os.path.join(os.environ.get("LocalAppData"), "alire", "msys64")) # Disable autoconfig of the community index, to prevent unintended use of # it in tests, besides the overload of fetching it - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "index.auto_community", "false") # Disable selection of toolchain to preserve older behavior. Tests that @@ -69,21 +69,21 @@ def prepare_env(config_dir, env): # Disable warning on old index, to avoid having to update index versions # when they're still compatible. - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "warning.old_index", "false") # Disable shared dependencies (keep old pre-2.0 behavior) not to break lots # of tests. The post-2.0 behavior will have its own tests. - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "dependencies.shared", "false") # Disable index auto-updates, which is not expected by most tests - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "index.auto_update", "0") # If distro detection is disabled via environment, configure so in alr if "ALIRE_TESTSUITE_DISABLE_DISTRO" in env: - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "distribution.disable_detection", "true") @@ -614,5 +614,5 @@ def unselect_compiler(): Leave compiler configuration as if "None" was selected by the user in the assistant. """ - run_alr("config", "--global", "--unset", "toolchain.use.gnat") - run_alr("config", "--global", "--unset", "toolchain.external.gnat") \ No newline at end of file + run_alr("settings", "--global", "--unset", "toolchain.use.gnat") + run_alr("settings", "--global", "--unset", "toolchain.external.gnat") diff --git a/testsuite/drivers/builds.py b/testsuite/drivers/builds.py index bfbb5fbc..09424b50 100644 --- a/testsuite/drivers/builds.py +++ b/testsuite/drivers/builds.py @@ -20,7 +20,7 @@ def enable_shared() -> None: """ Enable shared builds """ - run_alr("config", "--global", "--set", "dependencies.shared", "true") + run_alr("settings", "--global", "--set", "dependencies.shared", "true") def are_shared() -> bool: @@ -28,7 +28,7 @@ def are_shared() -> bool: Return True if shared builds are enabled """ try: - return run_alr("config", "--global", "--get", + return run_alr("settings", "--global", "--get", "dependencies.shared").out.strip().lower() == "true" except: return False diff --git a/testsuite/drivers/driver/docker_nested.py b/testsuite/drivers/driver/docker_nested.py index cce50544..642552e0 100644 --- a/testsuite/drivers/driver/docker_nested.py +++ b/testsuite/drivers/driver/docker_nested.py @@ -43,7 +43,7 @@ def main(): os.environ["ALR_PATH"] = "/usr/bin/alr" # Must match docker volume mount # Disable autoconfig of the community index, to prevent unintended use - run_alr("config", "--global", "--set", "index.auto_community", "false") + run_alr("settings", "--global", "--set", "index.auto_community", "false") # Disable selection of toolchain. Tests that # require a configured compiler will have to set it up explicitly. @@ -51,7 +51,7 @@ def main(): # Disable warning on old index, to avoid having to update index versions # when they're still compatible. - run_alr("config", "--global", "--set", "warning.old_index", "false") + run_alr("settings", "--global", "--set", "warning.old_index", "false") # indexes to use if 'indexes' in test_env: diff --git a/testsuite/drivers/driver/python_script.py b/testsuite/drivers/driver/python_script.py index 8e4e25a6..1b30d8d5 100644 --- a/testsuite/drivers/driver/python_script.py +++ b/testsuite/drivers/driver/python_script.py @@ -169,7 +169,7 @@ class PythonScriptDriver(BaseDriver): # Activate shared builds. Using "-c" is needed as the environment # still isn't activated at the driver script level. run_alr("-c", pristine_env["ALR_CONFIG"], - "config", "--global", "--set", + "settings", "--global", "--set", "dependencies.shared", "true") p = self.run_script(copy.deepcopy(pristine_env)) self.check_result(p) diff --git a/testsuite/drivers/helpers.py b/testsuite/drivers/helpers.py index 4446697f..b6140321 100644 --- a/testsuite/drivers/helpers.py +++ b/testsuite/drivers/helpers.py @@ -292,4 +292,4 @@ class FileLock(): # Release the file lock import fcntl fcntl.flock(self.lock_file.fileno(), fcntl.LOCK_UN) - self.lock_file.close() \ No newline at end of file + self.lock_file.close() diff --git a/testsuite/tests/alias/basic/test.py b/testsuite/tests/alias/basic/test.py index 163a8041..e19e72a1 100644 --- a/testsuite/tests/alias/basic/test.py +++ b/testsuite/tests/alias/basic/test.py @@ -15,7 +15,7 @@ run_alr('get', 'hello') os.chdir(glob('hello*')[0]) # Define an alias locally -run_alr('config', '--set', 'alias.my_alias', 'exec -- echo Test an alias') +run_alr('settings', '--set', 'alias.my_alias', 'exec -- echo Test an alias') # Use the alias p = run_alr('my_alias', diff --git a/testsuite/tests/build_profile/last_profile/test.py b/testsuite/tests/build_profile/last_profile/test.py index b4d40154..92f74fc3 100644 --- a/testsuite/tests/build_profile/last_profile/test.py +++ b/testsuite/tests/build_profile/last_profile/test.py @@ -11,19 +11,19 @@ init_local_crate("xxx") run_alr("build") assert_match(".*last_build_profile=xxx=DEVELOPMENT.*", - run_alr("config").out) + run_alr("settings").out) # Check explicit profile in command line run_alr("build", "--release") assert_match(".*last_build_profile=xxx=RELEASE.*", - run_alr("config").out) + run_alr("settings").out) # Check implicit profile when build is indirect is last that was used: run_alr("run") # Causes a build with the last used profile assert_match(".*last_build_profile=xxx=RELEASE.*", - run_alr("config").out) + run_alr("settings").out) # Check explicit profile requested in the manifest @@ -33,6 +33,6 @@ with open(alr_manifest(), "at") as manifest: run_alr("build") assert_match(".*last_build_profile=xxx=VALIDATION.*", - run_alr("config").out) + run_alr("settings").out) print('SUCCESS') diff --git a/testsuite/tests/dockerized/misc/failed-auto-update/test.py b/testsuite/tests/dockerized/misc/failed-auto-update/test.py index cb75457e..bed898b0 100644 --- a/testsuite/tests/dockerized/misc/failed-auto-update/test.py +++ b/testsuite/tests/dockerized/misc/failed-auto-update/test.py @@ -19,11 +19,11 @@ run_alr("index", "--name", "test", "--add", INDEX) run_alr("show", "libhello") # Enable autoupdate -run_alr("config", "--global", "--set", "index.auto_update", "1") +run_alr("settings", "--global", "--set", "index.auto_update", "1") # Ensure next `alr show` will trigger an update -run_alr("config", "--global", "--unset", "index.last_update") -run_alr("config", "--global", "--set", "index.auto_update_asked", "true") +run_alr("settings", "--global", "--unset", "index.last_update") +run_alr("settings", "--global", "--set", "index.auto_update_asked", "true") # Prepare a copy of `unshare` that can be run as regular user run(["cp", "/usr/bin/unshare", "/tmp"]).check_returncode() diff --git a/testsuite/tests/index/auto-update/test.py b/testsuite/tests/index/auto-update/test.py index 525191e4..1d5889de 100644 --- a/testsuite/tests/index/auto-update/test.py +++ b/testsuite/tests/index/auto-update/test.py @@ -16,7 +16,7 @@ assert "auto_update_asked = true\n" not in lines_of(CONFIG_FILE), \ # Auto updates are disabled by default by the python harness, to maintain # compatibility of older tests. We disable the disabling now. -run_alr("config", "--global", "--unset", "index.auto_update") +run_alr("settings", "--global", "--unset", "index.auto_update") # This was set to 0 to disable updates # After using the index, the user will have been asked diff --git a/testsuite/tests/index/branch-mismatch/test.py b/testsuite/tests/index/branch-mismatch/test.py index 8d3145aa..ac61a853 100644 --- a/testsuite/tests/index/branch-mismatch/test.py +++ b/testsuite/tests/index/branch-mismatch/test.py @@ -25,7 +25,7 @@ os.system('git ' + gitconfig + ' commit -q -m initialize') os.chdir(start) # Enable the warning we are trying to test -run_alr("config", "--global", "--set", "warning.old_index", "true") +run_alr("settings", "--global", "--set", "warning.old_index", "true") # Run the test. No alr version should use 'master' for the community index. # This produces a warning only, because the index version is valid. diff --git a/testsuite/tests/index/local-index-not-found/test.py b/testsuite/tests/index/local-index-not-found/test.py index 3997eebb..4add3de6 100644 --- a/testsuite/tests/index/local-index-not-found/test.py +++ b/testsuite/tests/index/local-index-not-found/test.py @@ -17,7 +17,7 @@ for d in ('no-such-directory', # Delete old configuration and indexes, but disable msys2 installation or # installation will be reattempted. rm('alr-config', recursive=True) - run_alr("config", "--global", "--set", "msys2.do_not_install", "true") + run_alr("settings", "--global", "--set", "msys2.do_not_install", "true") prepare_indexes('alr-config', '.', {'bad_index': {'dir': d, 'in_fixtures': False}}) diff --git a/testsuite/tests/index/old-compat-version/test.py b/testsuite/tests/index/old-compat-version/test.py index c69accbc..d65e3f8c 100644 --- a/testsuite/tests/index/old-compat-version/test.py +++ b/testsuite/tests/index/old-compat-version/test.py @@ -9,7 +9,7 @@ import re import os # Enable the warning we are trying to test -run_alr("config", "--global", "--set", "warning.old_index", "true") +run_alr("settings", "--global", "--set", "warning.old_index", "true") # Run a command that loads the index. This produces a warning only, because the # index version is old but valid. diff --git a/testsuite/tests/init/interactive-inputs/test.py b/testsuite/tests/init/interactive-inputs/test.py index e874729e..f453aa12 100644 --- a/testsuite/tests/init/interactive-inputs/test.py +++ b/testsuite/tests/init/interactive-inputs/test.py @@ -41,7 +41,7 @@ def check(descr: str = "", name: str = ""): shutil.rmtree("xxx") # Unset the user information so it is re-asked next time - run_alr('config', '--global', '--unset', 'user.name') + run_alr('settings', '--global', '--unset', 'user.name') # Other fields are not being set because they use the defaults so don't # require unsetting. diff --git a/testsuite/tests/init/user-input-validation/test.py b/testsuite/tests/init/user-input-validation/test.py index 07cbbd23..3fb5f99d 100644 --- a/testsuite/tests/init/user-input-validation/test.py +++ b/testsuite/tests/init/user-input-validation/test.py @@ -10,9 +10,9 @@ from drivers.helpers import content_of # Preconfigure needed fields name = "Äł O'Reilly O\"Raro" -run_alr("config", "--global", "--set", "user.email", "abc@de.com") -run_alr("config", "--global", "--set", "user.github_login", "abcde") -run_alr("config", "--global", "--set", "user.name", name) +run_alr("settings", "--global", "--set", "user.email", "abc@de.com") +run_alr("settings", "--global", "--set", "user.github_login", "abcde") +run_alr("settings", "--global", "--set", "user.name", name) # Create crate run_alr("init", "--bin", "xxx") diff --git a/testsuite/tests/install/default-location/test.py b/testsuite/tests/install/default-location/test.py index f5b0350b..9239a695 100644 --- a/testsuite/tests/install/default-location/test.py +++ b/testsuite/tests/install/default-location/test.py @@ -17,7 +17,7 @@ else: # Disable msys2 as the home change doesn't sit well with it and we don't need it here. # This is a workaround because trying to disable it via config doesn't work on 1st run: -# run_alr("config", "--global", "--set", "msys2.do_not_install", "true") +# run_alr("settings", "--global", "--set", "msys2.do_not_install", "true") if on_windows(): os.makedirs(os.path.join(os.environ["USERPROFILE"], ".cache", "alire", "msys64")) diff --git a/testsuite/tests/misc/git-ungit/test.py b/testsuite/tests/misc/git-ungit/test.py index 4054d27c..ff59ce4c 100644 --- a/testsuite/tests/misc/git-ungit/test.py +++ b/testsuite/tests/misc/git-ungit/test.py @@ -37,7 +37,7 @@ for wanted in [False, True]: if not wanted: # Enable for next round - run_alr("config", "--global", "--set", + run_alr("settings", "--global", "--set", "dependencies.git.keep_repository", "true") # Cleanup for next round diff --git a/testsuite/tests/publish/submit-request-cancel/test.py b/testsuite/tests/publish/submit-request-cancel/test.py index 548de068..4931be90 100644 --- a/testsuite/tests/publish/submit-request-cancel/test.py +++ b/testsuite/tests/publish/submit-request-cancel/test.py @@ -35,11 +35,11 @@ if os.environ.get("GH_USERNAME", "") == "": print("SKIP: GH_USERNAME not set") sys.exit(0) else: - run_alr("config", "--global", "--set", + run_alr("settings", "--global", "--set", "user.github_login", os.environ["GH_USERNAME"]) # Configure the testing remote index -run_alr("config", "--global", "--set", "index.repository_name", "test-index") +run_alr("settings", "--global", "--set", "index.repository_name", "test-index") # Clone a simple crate not already in the index with a local remote subprocess.run(["gh", "repo", "clone", diff --git a/testsuite/tests/config/basics/test.py b/testsuite/tests/settings/basics/test.py similarity index 68% rename from testsuite/tests/config/basics/test.py rename to testsuite/tests/settings/basics/test.py index a8dcd7ba..8c57e87d 100644 --- a/testsuite/tests/config/basics/test.py +++ b/testsuite/tests/settings/basics/test.py @@ -1,5 +1,5 @@ """ -Check basic features of the alr config command +Check basic features of the alr settings command """ import os @@ -9,19 +9,19 @@ from glob import glob from drivers.alr import run_alr def invalid_key(*args): - print("Running: alr config %s" % " ".join([item for item in args])) + print("Running: alr settings %s" % " ".join([item for item in args])) - p = run_alr('config', *args, complain_on_error=False, quiet=False) + p = run_alr('settings', *args, complain_on_error=False, quiet=False) assert p.status != 0, "command should fail" - assert "Invalid configuration key" in p.out, \ + assert "Invalid setting key" in p.out, \ "Missing error message in: '%s" % p.out def invalid_builtin(*args): - print("Running: alr config %s" % " ".join([item for item in args])) + print("Running: alr settings %s" % " ".join([item for item in args])) - p = run_alr('config', *args, complain_on_error=False, quiet=False) + p = run_alr('settings', *args, complain_on_error=False, quiet=False) assert p.status != 0, "command should fail" @@ -30,9 +30,9 @@ def invalid_builtin(*args): def check_value(key, expected_value, local=True): if local: - get = run_alr('config', '--get', key) + get = run_alr('settings', '--get', key) else: - get = run_alr('config', '--global', '--get', key) + get = run_alr('settings', '--global', '--get', key) assert get.out == expected_value + "\n", "Got '%s'" % get.out def set_get_unset(key, value, image=None): @@ -41,24 +41,24 @@ def set_get_unset(key, value, image=None): image = value # The key should not be defined - get1 = run_alr('config', '--global', '--get', key, complain_on_error=False) + get1 = run_alr('settings', '--global', '--get', key, complain_on_error=False) assert get1.status != 0, 'Should not be defined' # Define it - run_alr('config', '--global', '--set', key, value) + run_alr('settings', '--global', '--set', key, value) # Check that it is defined check_value(key, image, local=False) # Unset it - run_alr('config', '--global', '--unset', key) + run_alr('settings', '--global', '--unset', key) # Check that is it not defined anymore - get3 = run_alr('config', '--global', '--get', key, complain_on_error=False) + get3 = run_alr('settings', '--global', '--get', key, complain_on_error=False) assert get3.status != 0, 'Should not be defined' ####################### -# invalid config keys # +# invalid settings keys # ####################### invalid_key('--get', '--global', '.test') invalid_key('--get', '--global', '_test.') @@ -86,12 +86,12 @@ set_get_unset('test.int', '42') set_get_unset('test.bool', 'true') set_get_unset('test.float', '0.2', image='2.00000000000000E-01') -################ -# Local config # -################ +################## +# Local settings # +################## # Check that local operations (default) fail if not in a crate context -p = run_alr('config', '--set', 'test.local', '42', complain_on_error=False) +p = run_alr('settings', '--set', 'test.local', '42', complain_on_error=False) assert p.status != 0, 'Should fail' # Get a create to have local context @@ -99,14 +99,14 @@ run_alr('get', 'hello') os.chdir(glob('hello*')[0]) # Local operation should now work -run_alr('config', '--set', 'test.local', '42') +run_alr('settings', '--set', 'test.local', '42') # Set a local and check its value -run_alr('config', '--set', 'test.override', '"is_local"') +run_alr('settings', '--set', 'test.override', '"is_local"') check_value('test.override', 'is_local') # Set a global and check that the local value is still returned -run_alr('config', '--set', '--global', 'test.override', '"is_global"') +run_alr('settings', '--set', '--global', 'test.override', '"is_global"') check_value('test.override', 'is_local') # Leave the crate context (local keys are not available anymore) @@ -116,6 +116,6 @@ os.chdir('..') check_value('test.override', 'is_global', local=False) # Remove the global key -run_alr('config', '--unset', '--global', 'test.override') +run_alr('settings', '--unset', '--global', 'test.override') print('SUCCESS') diff --git a/testsuite/tests/config/basics/test.yaml b/testsuite/tests/settings/basics/test.yaml similarity index 100% rename from testsuite/tests/config/basics/test.yaml rename to testsuite/tests/settings/basics/test.yaml diff --git a/testsuite/tests/config/cache-relocation/test.py b/testsuite/tests/settings/cache-relocation/test.py similarity index 65% rename from testsuite/tests/config/cache-relocation/test.py rename to testsuite/tests/settings/cache-relocation/test.py index a6e4c63e..d8868c22 100644 --- a/testsuite/tests/config/cache-relocation/test.py +++ b/testsuite/tests/settings/cache-relocation/test.py @@ -12,15 +12,15 @@ else: drive = "" # Default cache location (inside test config dir) -assert_match(r".*cache folder:[^\n]*config__cache-relocation/alr-config/cache", +assert_match(r".*cache folder:[^\n]*settings__cache-relocation/alr-config/cache", run_alr("version").out.replace("\\", "/")) # Check toolchain location inside cache location -assert_match(r".*toolchain folder:[^\n]*config__cache-relocation/alr-config/cache/toolchains", +assert_match(r".*toolchain folder:[^\n]*settings__cache-relocation/alr-config/cache/toolchains", run_alr("version").out.replace("\\", "/")) -# Override via config (takes precedence) -run_alr("config", "--global", "--set", "cache.dir", f"{drive}/relocated-to-root") +# Override via settings (takes precedence) +run_alr("settings", "--global", "--set", "cache.dir", f"{drive}/relocated-to-root") assert_match(r".*cache folder:[^\n]*/relocated-to-root", run_alr("version").out.replace("\\", "/")) @@ -28,8 +28,8 @@ assert_match(r".*cache folder:[^\n]*/relocated-to-root", assert_match(r".*toolchain folder:[^\n]*/relocated-to-root/toolchains", run_alr("version").out.replace("\\", "/")) -# Check toolchain override via config (takes precedence over cache override) -run_alr("config", "--global", "--set", "toolchain.dir", f"{drive}/relocated-toolchains") +# Check toolchain override via settings (takes precedence over cache override) +run_alr("settings", "--global", "--set", "toolchain.dir", f"{drive}/relocated-toolchains") assert_match(r".*toolchain folder:[^\n]*/relocated-toolchains", run_alr("version").out.replace("\\", "/")) diff --git a/testsuite/tests/config/cache-relocation/test.yaml b/testsuite/tests/settings/cache-relocation/test.yaml similarity index 100% rename from testsuite/tests/config/cache-relocation/test.yaml rename to testsuite/tests/settings/cache-relocation/test.yaml diff --git a/testsuite/tests/config/community-disable/test.py b/testsuite/tests/settings/community-disable/test.py similarity index 100% rename from testsuite/tests/config/community-disable/test.py rename to testsuite/tests/settings/community-disable/test.py diff --git a/testsuite/tests/config/community-disable/test.yaml b/testsuite/tests/settings/community-disable/test.yaml similarity index 100% rename from testsuite/tests/config/community-disable/test.yaml rename to testsuite/tests/settings/community-disable/test.yaml diff --git a/testsuite/tests/config/distro-disable/test.py b/testsuite/tests/settings/distro-disable/test.py similarity index 88% rename from testsuite/tests/config/distro-disable/test.py rename to testsuite/tests/settings/distro-disable/test.py index ecc1278d..1e45faa2 100644 --- a/testsuite/tests/config/distro-disable/test.py +++ b/testsuite/tests/settings/distro-disable/test.py @@ -4,7 +4,7 @@ Verify that disabling distro detection works as intended from drivers.alr import run_alr, distro_is_known -run_alr("config", "--global", +run_alr("settings", "--global", "--set", "distribution.disable_detection", "true") assert not distro_is_known(), "Unexpected distro detection" diff --git a/testsuite/tests/config/distro-disable/test.yaml b/testsuite/tests/settings/distro-disable/test.yaml similarity index 100% rename from testsuite/tests/config/distro-disable/test.yaml rename to testsuite/tests/settings/distro-disable/test.yaml diff --git a/testsuite/tests/config/distro-override/test.py b/testsuite/tests/settings/distro-override/test.py similarity index 91% rename from testsuite/tests/config/distro-override/test.py rename to testsuite/tests/settings/distro-override/test.py index 30be498c..afb32837 100644 --- a/testsuite/tests/config/distro-override/test.py +++ b/testsuite/tests/settings/distro-override/test.py @@ -7,14 +7,14 @@ from drivers.asserts import assert_match # Overriding distro detection. We force Debian as our tests run in Ubuntu and # many other distros so it is only giving a false positive on Debian. -run_alr("config", "--global", +run_alr("settings", "--global", "--set", "distribution.override", "debian") assert_match(".*distribution:[^\n]*DEBIAN", run_alr("version").out) # Disabling distro detection takes precedence -run_alr("config", "--global", +run_alr("settings", "--global", "--set", "distribution.disable_detection", "true") assert_match(".*distribution:[^\n]*DISTRIBUTION_UNKNOWN", diff --git a/testsuite/tests/config/distro-override/test.yaml b/testsuite/tests/settings/distro-override/test.yaml similarity index 100% rename from testsuite/tests/config/distro-override/test.yaml rename to testsuite/tests/settings/distro-override/test.yaml diff --git a/testsuite/tests/config/early-loading/test.py b/testsuite/tests/settings/early-loading/test.py similarity index 77% rename from testsuite/tests/config/early-loading/test.py rename to testsuite/tests/settings/early-loading/test.py index 40f45b3b..fbbeffb2 100644 --- a/testsuite/tests/config/early-loading/test.py +++ b/testsuite/tests/settings/early-loading/test.py @@ -17,13 +17,13 @@ expected = "test_value=42\n" # Verify proper loading with both short and long config options assert_eq(expected, - run_alr("-c", custom_config, "config", "--global").out) + run_alr("-c", custom_config, "settings", "--global").out) assert_eq(expected, - run_alr(f"--config={custom_config}", "config", "--global").out) + run_alr(f"--config={custom_config}", "settings", "--global").out) # Verify also when using environment variable os.environ["ALR_CONFIG"] = os.path.abspath(custom_config) assert_eq(expected, - run_alr("config", "--global").out) + run_alr("settings", "--global").out) print('SUCCESS') diff --git a/testsuite/tests/config/early-loading/test.yaml b/testsuite/tests/settings/early-loading/test.yaml similarity index 100% rename from testsuite/tests/config/early-loading/test.yaml rename to testsuite/tests/settings/early-loading/test.yaml diff --git a/testsuite/tests/config/missing-config-default/my_index/he/hello/hello-1.0.0.toml b/testsuite/tests/settings/missing-config-default/my_index/he/hello/hello-1.0.0.toml similarity index 100% rename from testsuite/tests/config/missing-config-default/my_index/he/hello/hello-1.0.0.toml rename to testsuite/tests/settings/missing-config-default/my_index/he/hello/hello-1.0.0.toml diff --git a/testsuite/tests/config/missing-config-default/my_index/he/hello/hello-1.0.1.toml b/testsuite/tests/settings/missing-config-default/my_index/he/hello/hello-1.0.1.toml similarity index 100% rename from testsuite/tests/config/missing-config-default/my_index/he/hello/hello-1.0.1.toml rename to testsuite/tests/settings/missing-config-default/my_index/he/hello/hello-1.0.1.toml diff --git a/testsuite/tests/config/missing-config-default/my_index/index.toml b/testsuite/tests/settings/missing-config-default/my_index/index.toml similarity index 100% rename from testsuite/tests/config/missing-config-default/my_index/index.toml rename to testsuite/tests/settings/missing-config-default/my_index/index.toml diff --git a/testsuite/tests/config/missing-config-default/my_index/li/libhello/libhello-1.0.0.toml b/testsuite/tests/settings/missing-config-default/my_index/li/libhello/libhello-1.0.0.toml similarity index 100% rename from testsuite/tests/config/missing-config-default/my_index/li/libhello/libhello-1.0.0.toml rename to testsuite/tests/settings/missing-config-default/my_index/li/libhello/libhello-1.0.0.toml diff --git a/testsuite/tests/config/missing-config-default/test.py b/testsuite/tests/settings/missing-config-default/test.py similarity index 100% rename from testsuite/tests/config/missing-config-default/test.py rename to testsuite/tests/settings/missing-config-default/test.py diff --git a/testsuite/tests/config/missing-config-default/test.yaml b/testsuite/tests/settings/missing-config-default/test.yaml similarity index 100% rename from testsuite/tests/config/missing-config-default/test.yaml rename to testsuite/tests/settings/missing-config-default/test.yaml diff --git a/testsuite/tests/config/relative_config_path/test.py b/testsuite/tests/settings/relative_config_path/test.py similarity index 88% rename from testsuite/tests/config/relative_config_path/test.py rename to testsuite/tests/settings/relative_config_path/test.py index 9e79fe2e..efb4e7a0 100644 --- a/testsuite/tests/config/relative_config_path/test.py +++ b/testsuite/tests/settings/relative_config_path/test.py @@ -10,7 +10,7 @@ from drivers.alr import run_alr from drivers.asserts import assert_eq from drivers.helpers import lines_of -run_alr("--config=.", "config", "--global", +run_alr("--config=.", "settings", "--global", "--set", "some_config_key", "true") diff --git a/testsuite/tests/config/relative_config_path/test.yaml b/testsuite/tests/settings/relative_config_path/test.yaml similarity index 100% rename from testsuite/tests/config/relative_config_path/test.yaml rename to testsuite/tests/settings/relative_config_path/test.yaml diff --git a/testsuite/tests/config/shared-deps/test.py b/testsuite/tests/settings/shared-deps/test.py similarity index 100% rename from testsuite/tests/config/shared-deps/test.py rename to testsuite/tests/settings/shared-deps/test.py diff --git a/testsuite/tests/config/shared-deps/test.yaml b/testsuite/tests/settings/shared-deps/test.yaml similarity index 100% rename from testsuite/tests/config/shared-deps/test.yaml rename to testsuite/tests/settings/shared-deps/test.yaml diff --git a/testsuite/tests/solver/compiler-selected/test.py b/testsuite/tests/solver/compiler-selected/test.py index 52b0527a..70a10ccf 100644 --- a/testsuite/tests/solver/compiler-selected/test.py +++ b/testsuite/tests/solver/compiler-selected/test.py @@ -20,7 +20,7 @@ alr_with("gnat*") match_solution("gnat=8888.0.0 (gnat_native)", escape=True) # Selecting another default will cause a corresponding change in the solution -run_alr("config", "--set", "toolchain.use.gnat", "gnat_cross_2=1") +run_alr("settings", "--set", "toolchain.use.gnat", "gnat_cross_2=1") run_alr("update") match_solution("gnat=1.0.0 (gnat_cross_2)", escape=True) diff --git a/testsuite/tests/toolchain/select-defaults/test.py b/testsuite/tests/toolchain/select-defaults/test.py index fadefe8d..f0c03873 100644 --- a/testsuite/tests/toolchain/select-defaults/test.py +++ b/testsuite/tests/toolchain/select-defaults/test.py @@ -10,7 +10,7 @@ from drivers.asserts import assert_match init_local_crate() # Re-config as if it was the first time running alr -run_alr("config", "--global", "--set", "toolchain.assistant", "true") +run_alr("settings", "--global", "--set", "toolchain.assistant", "true") # A command requiring a workspace will trigger the assistant p = run_alr("show", quiet=False) diff --git a/testsuite/tests/toolchain/select-while-missing/test.py b/testsuite/tests/toolchain/select-while-missing/test.py index 66fe3626..2ce31dc1 100644 --- a/testsuite/tests/toolchain/select-while-missing/test.py +++ b/testsuite/tests/toolchain/select-while-missing/test.py @@ -10,7 +10,7 @@ from drivers.alr import run_alr run_alr("toolchain", "--select", "gnat_native", "gprbuild") # Configure an invalid compiler -run_alr("config", "--global", "--set", "toolchain.use.gnat", "gnat_nono=1.2.3") +run_alr("settings", "--global", "--set", "toolchain.use.gnat", "gnat_nono=1.2.3") # This must succeed run_alr("toolchain", "--select", "gnat_native=1.0") diff --git a/testsuite/tests/workflows/edit/test.py b/testsuite/tests/workflows/edit/test.py index 8f7bf6a6..b7c8f89f 100644 --- a/testsuite/tests/workflows/edit/test.py +++ b/testsuite/tests/workflows/edit/test.py @@ -14,7 +14,7 @@ run_alr('get', 'libhello') os.chdir(glob('libhello*')[0]) # Set GNATstudio as prefered editor -run_alr('config', '--set', 'editor.cmd', 'gnatstudio -P ${GPR_FILE}') +run_alr('settings', '--set', 'editor.cmd', 'gnatstudio -P ${GPR_FILE}') gs = shutil.which('gnatstudio') @@ -30,13 +30,13 @@ else: assert_match(".*Please specify a project file with --project=.*", p.out) # Set an editor that doesn't exist (different than GNAT Studio) -run_alr('config', '--set', 'editor.cmd', 'doesnt_exist arg1 ab${GPR_FILE}ab arg3') +run_alr('settings', '--set', 'editor.cmd', 'doesnt_exist arg1 ab${GPR_FILE}ab arg3') p = run_alr('edit', '--project=project1.gpr', complain_on_error=False) assert_match("ERROR: 'doesnt_exist' not available or not in PATH.*", p.out) print(p.out) # Use echo as an editor to check command line args -run_alr('config', '--set', 'editor.cmd', 'echo arg1 ab${GPR_FILE}ab arg3') +run_alr('settings', '--set', 'editor.cmd', 'echo arg1 ab${GPR_FILE}ab arg3') p = run_alr('edit', '--project=project1.gpr') assert_match("arg1 abproject1.gprab arg3", p.out) -- 2.39.5