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

[feature] Support nested execution in platform: system commands #889

Open
shellscape opened this issue Jun 5, 2023 · 4 comments
Open

[feature] Support nested execution in platform: system commands #889

shellscape opened this issue Jun 5, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@shellscape
Copy link

Is your feature request related to a problem? Please describe.

While trying to get around #888 without creating a separate bash script, I attempted to use the MOON_PROJECT_ROOT environment variable in a command with platform: system.

  test:
    command: node --title $projectAlias:test ../../node_modules/ava/entrypoints/cli.mjs $(echo $MOON_PROJECT_ROOT)
    inputs:
      - src
      - test
    platform: system

The result was:

[DEBUG 11:35:05] moon_process::command_inspector  Running command /bin/zsh -c 'node --title svc-test:test ../../node_modules/ava/entrypoints/cli.mjs '\''$(echo'\'' '\''$MOON_PROJECT_ROOT)'\''' 

I also tried backticks with a similar result:

  test:
    command: node --title $projectAlias:test ../../node_modules/ava/entrypoints/cli.mjs `echo $MOON_PROJECT_ROOT`
    inputs:
      - src
      - test
    platform: system

It looks like the argument parsing needs a bit more massaging to make it bash-compatible yet, but that's to be expected.

Describe the solution you'd like

I'd like to use backticks or the $() blocks for nested execution. This likely requires closer integration with the shell and probably not something that moon is setup for at the moment, but I'd still like to get it down as a want and nice-to-have.

Describe alternatives you've considered

Using a separate bash script works, but that's a detriment to DX.

Additional context

@shellscape shellscape added the enhancement New feature or request label Jun 5, 2023
@milesj
Copy link
Collaborator

milesj commented Jun 5, 2023

@shellscape

Arg parsing comes from a third-party library, so I don't have a lot of control of it right now.

You can probably try the array form which bypasses arg parsing:

  test:
    command: 
      - node 
      - --title 
      - $projectAlias:test 
      - ../../node_modules/ava/entrypoints/cli.mjs 
      - $(echo $MOON_PROJECT_ROOT)
    inputs:
      - src
      - test
    platform: system

@shellscape
Copy link
Author

Good call. Gave that a shot and looks like the parser is making it a string, which doesn't allow the nested execution. '\''$(echo $MOON_PROJECT_ROOT)'\''' - it's no worries, I get you're limited at the moment. Good for tracking though.

@ilyasotkov
Copy link
Contributor

ilyasotkov commented Jun 19, 2023

Should this be considered a bug? I saw this example in the documentation:

tasks:
  native:
    command: 'echo $SHELL'
    options:
      shell: true

which I think implies that it will print the name of the shell used and not just the string $SHELL.

Can work around with:

tasks:
  native:
    command: bash -c "echo $SHELL"
    options:
      shell: true

Edit: apparently I'm talking about a different issue (shell variables vs nested execution), but both seem like a bug (bad UX) since shell features randomly don't work. I think users expect to be able to copy-paste their shell script file contents under command: |, and have it work with no hiccups.

@milesj
Copy link
Collaborator

milesj commented Jun 20, 2023

This PR (#928) will fix the quoting, so $(echo $MOON_PROJECT_ROOT) should work once it lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants