alirezanet / Husky.Net

Git hooks made easy with Husky.Net internal task runner! 🐶 It brings the dev-dependency concept to the .NET world!
https://alirezanet.github.io/Husky.Net/
MIT License
632 stars 29 forks source link

Unexpected parameter(s) error with ${staged} variable #73

Closed MarkusGnigler closed 1 year ago

MarkusGnigler commented 1 year ago

Version

v0.5.4

Details

I want format my code with only staged files, so i test the ${staged} variable with an c# script for this. If i change ${staged} to some hardcoded values e.g. "arg1" it works as expected.

When i run husky i got following errors:

Unexpected parameter(s):
<.husky/test.csx>

Husky v0.5.4

USAGE
  husky exec <path> [options]

DESCRIPTION
  Execute a csharp script (.csx) file

PARAMETERS
* path              The script file to execute

  -a|--args         Arguments to pass to the script Default: .
  --no-cache        Disable caching Default: "False".
  --no-color        Disable color output Default: "False".
  -v|--verbose      Enable verbose output Default: "False".
  -h|--help         Shows help text.

  ? Task 'exec-test' failed in 286ms

A simple echo task works fine but every arg to another command won't.

:heavy_check_mark:

  {
      "command": "cmd",
      "args": [
        "/c",
        "echo",
        "${staged}"
      ]
    },

:x:

    {
      "name": "Run dotnet format",
      "command": "dotnet",
      "args": [
        "format",
        "--files",
        "${staged}"
      ],
      "include": [
        "**/*.cs"
      ]
    },

Steps to reproduce

  1. Create c# test script in .husky/test.csx to print the args
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Test: {0}", string.Join(",", Args));

return 1;
  1. Create a task step in .husky/task-runner.json
{
  "tasks": [
    {
      "name": "exec-test",
      "command": "dotnet",
      "args": [
        "husky",
        "exec",
        ".husky/test.csx",
        "--args",
        "${staged}"
      ]
    }
  ]
}
  1. Run it
dotnet husky run
alirezanet commented 1 year ago

Hi @MarkusGnigler,

I reproduced your example and it worked as expected. 🤔

image

are you sure you didn't miss anything in your example?

MarkusGnigler commented 1 year ago

Thanks for reply.

Strange. I play a little and try with powershell and wsl-debian. It looks like the runner couldn't use the staged variable i guess?

The following command runs fine

dotnet husky exec .husky/test.csx --args arg1 arg2

and dotnet husky run get a exec error .

Please can you share your task in task-runner.json, could be that i messed up something there.

alirezanet commented 1 year ago

This is exactly your example:

image

🤷‍♂️

alirezanet commented 1 year ago

It might be related the terminal you are using, can you try PowerShell if you're using something else? it should work for you. I tested on two different machines with two different OS, didn't face this problem

MarkusGnigler commented 1 year ago

Sorry for the unnecessary disturbance! I don't know the root causes but seems to be that my company PC is to hard restricted. It work's on my private PC as expected.

alirezanet commented 4 months ago

Hi @alastair-todd, Why are you returning 1 if you don't expect an error? any non-zero exit code is considered an error. in that example I was expecting an error.