mbl-35 / wslctl

Provide a single command wslctl to create, backup and manage WSL (Windows Subsystem for Linux) instances on a windows host
0 stars 1 forks source link

Optionals arguments not correctly interpreted #1

Closed mbl-35 closed 3 years ago

mbl-35 commented 3 years ago

wslctl: v1.0.0 wins10

When using with powershell inerpreter, no pb:

PS> powershell .\src\wslctl.ps1 --help
Usage:
   wslctl COMMAND [ARG...]
   wslctl [ --help | --version ]
...

But with the generated executable, the command line does not pass '--' but '-' :

PS> wslctl --help
Error: Command '-help' is not defined
PS > wslctl ---help
Usage:
   wslctl COMMAND [ARG...]
   wslctl [ --help | --version ]
...

Same from MSDos console:

C:\Users>wslctl --help
Error: Command '-help' is not defined

C:\Users>wslctl ---help

Usage:
   wslctl COMMAND [ARG...]
   wslctl [ --help | --version ]
mbl-35 commented 3 years ago

Issue from ps2exe: https://github.com/MScholtes/PS2EXE/issues/54#issuecomment-897698775 If I want to keep UN*x behavior, I need to change my parsing parameter method (but no powershell names...)

mbl-35 commented 3 years ago

v1.0.1

Still have error with .exe

--force : toot many arguments
--no-user: invalid parameter
--v1 invalid parameter
mbl-35 commented 3 years ago

Simple test.ps1

$args.count
$args | ConvertTo-Json

ps1 tests:

PS > .\test.ps1 arg1 arg2 arg3
3
[
    "arg1",
    "arg2",
    "arg3"
PS > .\test.ps1 arg1 arg2 arg3 --toto
4
[
    "arg1",
    "arg2",
    "arg3",
    "--toto"
]

Create binary with Invoke-ps2exe -inputFile test.ps1 -outputFile test.exe -x64 and do same tests:

PS > .\test.exe arg1 arg2 arg3 --toto
5
[
    "arg1",
    "arg2",
    "arg3",
    "-toto",
    true
]
PS > .\test.exe arg1 arg2 arg3 ---toto
5
[
    "arg1",
    "arg2",
    "arg3",
    "--toto",
    true
]
PS > .\test.exe arg1 arg2 arg3 -toto
5
[
    "arg1",
    "arg2",
    "arg3",
    "-toto",
    true
]
PS > .\test.exe arg1 arg2 arg3 -toto --toto
7
[
    "arg1",
    "arg2",
    "arg3",
    "-toto",
    true,
    "-toto",
    true
]

Seems that ps2exe add boolean when parameter starts with '-'.

Solution: Filter args New test.ps1

$args = $args | Where {$_ -is [String]}  # Filter
$args.count
$args | ConvertTo-Json

Produce same result calling the ps1 file.

Results exe recompiled with filter

PS > .\test.exe arg1 arg2 arg3 --toto
4
[
    "arg1",
    "arg2",
    "arg3",
    "-toto"
]
PS > .\test.exe arg1 arg2 arg3 -toto
4
[
    "arg1",
    "arg2",
    "arg3",
    "-toto"
]
PS > .\test.exe arg1 arg2 arg3 ---toto
4
[
    "arg1",
    "arg2",
    "arg3",
    "--toto"
]
PS > .\test.exe arg1 arg2 arg3 -toto --toto
5
[
    "arg1",
    "arg2",
    "arg3",
    "-toto",
    "-toto"
]
mbl-35 commented 3 years ago

Resolved by release 1.0.2.