casey / just

🤖 Just a command runner
https://just.systems
Creative Commons Zero v1.0 Universal
20.06k stars 448 forks source link

Using recipes with argument and without as a different recipes #1545

Open JJBT opened 1 year ago

JJBT commented 1 year ago

Is it possible to use recipes with argument and without as a different recipes without overriding? If not i think it would be great idea to make it works

recipe:
    command

recipe NAME:
    another_command {{ NAME }}

In my case command is a list of some objects and another_command is a list of the same objects but with grepping by the NAME.

casey commented 1 year ago

This is currently not possible, and I think tricky to implement without being very weird. I would be open to this if the implementation were very simple though.

runeimp commented 1 year ago

@JJBT Though I like the idea as it could potentially avoid lots of otherwise necessary scripting you can do some shebang shell scripting to handle these situations

# UNIX Shell Test
shell_test *NAME:
    #!/bin/sh

    if [ '{{NAME}}' = '' ]; then
        command
    else
        another_command "{{NAME}}"
    fi

or using PowerShell in a cross-platform setup

set windows-shell := ["powershell", "-c"] # To use PowerShell Desktop instead of Core on Windows
set shell := ["pwsh", "-c"] # PowerShell Core (Multi-Platform)
shebang := if os() == 'windows' { 'powershell' } else { '/usr/bin/env pwsh' } # Switch 'powershell' with 'pwsh' for PowerShell Core

# PowerShell Test
pwsh_test *NAME:
    #!{{shebang}}

    $NAME = "{{NAME}}"

    if ($NAME.Length -eq 0) {
        command
    } else {
        another_command "$NAME"
    }