Coder Social home page Coder Social logo

`[script]` recipes about just HOT 8 CLOSED

casey avatar casey commented on July 29, 2024
`[script]` recipes

from just.

Comments (8)

nk9 avatar nk9 commented on July 29, 2024 1

I'd just like to point out that the current setup allows interpolation in all recipes, so the syntax is able to deal with that very simply. If it were possible for some recipes to disallow interpolation, it wouldn't be at all straightforward for the syntax to distinguish those. We'd have to branch at the point of the [script] attribute and create a category of non-interpolation recipes which duplicate the recipe code. I'm not sure it would be worth the effort.

I'm not taking a position on whether the attribute is worthwhile, but if there's not a clear case for it then my preference would be to not add it.

from just.

casey avatar casey commented on July 29, 2024 1

I'm now leaning towards not doing this, and instead adding a [script] recipe annotation which is simply a way to create a shebang recipe with cross-platform syntax, see #1479.

from just.

indigoviolet avatar indigoviolet commented on July 29, 2024

Is this a common tripping hazard for new users? TBH, this doesn't resonate with me as a a big pain point that is worth the loss of functionality (no interpolation, no echoing, have to remember to export variables) with not much new functionality enabled, complexity added in the interim:

  • interpolation of {{ }} and escaping: I do use this interpolation more often than I escape it. Perhaps the flag we're looking for is no-interpolation instead

  • shebang line/interpreter customization -- has not been a problem for me (but I don't use just on windows)

  • set positional-arguments: I haven't understood why this isn't on by default - is there a downside?

I already avoid shebang recipes as much as possible: (1) too many footguns in shell scripts (2) justfiles are not good development environments for complex scripts. I can already write a shell script and execute it from just if needed.

My suggestion would be to instead aim to not send users to shebang/script recipes. In that context, I would like to make it easier to treat other recipes in the file as functions -- not necessary syntactically, but in the sense of making it easy to compose complex recipes from simpler ones; there are some awkward edges like requiring -f {{ justfile() }}, constructing arguments by string concatenation, conditionals being expressions.

from just.

casey avatar casey commented on July 29, 2024

I should go back and look at issues, discussions, and discord chat, but just going on memory, there are some common tripping hazards that this would avoid:

  • Very common: Confusion about how to prevent {{…}} interpolations from being split by the shell. Needing to use '{{…}}', which is pretty ugly and verbose, doesn't work if an argument has ' in it.
  • Very common: Desire to set variables in the middle of a recipe.
  • Occasional: Shebang inconsistencies.

set positional-arguments isn't the default just because it can break some custom shells (namely old versions of powershell), but it's likely to become the default in a new edition.

It would be interesting to see how common shebang recipes are. One could use janus to find out.

Can you elaborate on the downsides? You mentioned loss of interpolation, echoing, and exporting variables:

  • Loss of interpolation: {{FOO}} would be replaced with $FOO (or $N if FOO is an argument), which is shorter and is the normal shell syntax.
  • Echoing: just could define a [script] recipe prelude which would be inserted at the beginning of script recipes. This could include set -x, which would turn on command echoing.
  • Exporting variables: In a future edition, set export could become the default, so you wouldn't have to remember to export variables.

from just.

casey avatar casey commented on July 29, 2024

By the way, thanks for the detailed feedback, I really appreciate it!

from just.

indigoviolet avatar indigoviolet commented on July 29, 2024
  1. Interpolation: I understand that with positional-arguments and export, we could get rid of interpolation for variables; what about for functions or expressions? ex {{ invocation_directory() }}?

Going in the other direction, I miss interpolation outside of recipes, concatenation is more verbose (#11). If this feature got added, we'd have the inverse confusion - why isn't {{..}} working in my recipe?

  1. Desire to set variables

I'm not understanding how [script] will address this trip hazard: it doesn't make it easier or eliminate the confusion between just variables and shell variables.

from just.

casey avatar casey commented on July 29, 2024

Going in the other direction, I miss interpolation outside of recipes, concatenation is more verbose (#11). If this feature got added, we'd have the inverse confusion - why isn't {{..}} working in my recipe?

Interesting point. I'm not sure if users would want {{…}} inside recipes, since the shell usually provides functionality to manipulate strings.

I'm not understanding how [script] will address this trip hazard: it doesn't make it easier or eliminate the confusion between just variables and shell variables.

I wasn't very clear, but I mentioned this because it's one of the main reasons that users need shebang recipes.

from just.

alexxbb avatar alexxbb commented on July 29, 2024

I'm looking forward to seeing this implemented, this is my biggest hurdle with just right now.

registry_main := "registry_main URL"

publish reg:
    ./scripts/publish.py {{ if reg == "main" { "{{registry_main}}" } else { "{{reg}}" } }}
>>just publish main
>>./scripts/publish.py {{registry_main}}

from just.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.