Skip to content

Commit

Permalink
Alr.Commands: add support for aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien-Chouteau committed Sep 28, 2021
1 parent d48e8df commit 9205502
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 4 deletions.
16 changes: 14 additions & 2 deletions doc/user-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ stay on top of `alr` new features.

## Release 1.2-dev

### User defined command aliases

PR [#853](https://github.com/alire-project/alire/pull/853)

It is now possible to define in configuration (local or global) aliases for the
`alr` commands.

```console
$ alr config --set --global alias.graph 'show --graph'
$ alr graph
```
Will run the `alr show` command with the `--graph` switch.

### New command `alr exec <command line>`

PR [#853](https://github.com/alire-project/alire/pull/)
PR [#853](https://github.com/alire-project/alire/pull/853)

This new command takes an executable and arguments and run them in the Alire
environment/context of the current crate.
Expand All @@ -17,7 +30,6 @@ environment/context of the current crate.
$ alr exec sh -c 'echo ${ALIRE}'
True
```
>>>>>>> Alr.Commands.Exec: new command to run executables/scripts in the Alire context

### Pass alr build switches to gprbuild

Expand Down
2 changes: 1 addition & 1 deletion src/alr/alr-commands-config.adb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ package body Alr.Commands.Config is
Trace.Always
(CLIC.Config.Info.List
(Alire.Config.DB,
Filter => "*",
Filter => ".*",
Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF));
when 1 =>
Trace.Always
Expand Down
2 changes: 1 addition & 1 deletion src/alr/alr-commands-config.ads
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ package Alr.Commands.Config is

overriding
function Usage_Custom_Parameters (Cmd : Command) return String is
("[--list] [--show-origin] [key_glob] |" &
("[--list] [--show-origin] [key_regex] |" &
" --get <key> |" &
" --set <key> <value> |" &
" --unset <key>");
Expand Down
30 changes: 30 additions & 0 deletions src/alr/alr-commands-topics-aliases.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
with AAA.Strings;

with CLIC.Subcommand;

package Alr.Commands.Topics.Aliases is

type Topic is new CLIC.Subcommand.Help_Topic with null record;

overriding
function Name (This : Topic) return CLIC.Subcommand.Identifier
is ("aliases");

overriding
function Title (This : Topic) return String
is ("User defined command aliases");

overriding
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.")
.New_Line
.Append ("For example the following command:")
.Append ("""$ alr config --set --global alias.graph 'show --graph'""")
.Append ("Defines a global alias for the 'show' command with a ")
.Append ("'--graph' switch.")
.New_Line
.Append ("""$ alr graph"" is equivalent to ""alr show --graph"""));

end Alr.Commands.Topics.Aliases;
5 changes: 5 additions & 0 deletions src/alr/alr-commands.adb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ with Alr.Commands.Withing;

with Alr.Commands.Topics.Naming_Convention;
with Alr.Commands.Topics.Toolchains;
with Alr.Commands.Topics.Aliases;

with GNAT.OS_Lib;
with GNAT.Source_Info;
Expand Down Expand Up @@ -408,6 +409,8 @@ package body Alr.Commands is
Create_Alire_Folders;

begin
Sub_Cmd.Load_Aliases (Alire.Config.DB);

Sub_Cmd.Execute;
Log ("alr " & Sub_Cmd.What_Command & " done", Detail);
exception
Expand Down Expand Up @@ -550,4 +553,6 @@ begin
-- Help topics --
Sub_Cmd.Register (new Topics.Naming_Convention.Topic);
Sub_Cmd.Register (new Topics.Toolchains.Topic);
Sub_Cmd.Register (new Topics.Aliases.Topic);

end Alr.Commands;
26 changes: 26 additions & 0 deletions testsuite/tests/alias/basic/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Basic check of alias definition in configuration
"""

from glob import glob
import os

from drivers.alr import run_alr
from drivers.asserts import assert_match

import re

# Get the "hello" project and enter its directory
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')

# Use the alias
p = run_alr('my_alias',
quiet=False) # -q will hide the output of the exec command

assert_match('Test an alias', p.out, flags=re.S)

print('SUCCESS')
3 changes: 3 additions & 0 deletions testsuite/tests/alias/basic/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
driver: python-script
indexes:
basic_index: {}

0 comments on commit 9205502

Please sign in to comment.