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

[Bug]scoop shim info : ERROR: Option -global not recognized. #5094

Closed
sebma opened this issue Aug 10, 2022 · 13 comments · Fixed by #5162
Closed

[Bug]scoop shim info : ERROR: Option -global not recognized. #5094

sebma opened this issue Aug 10, 2022 · 13 comments · Fixed by #5162
Labels

Comments

@sebma
Copy link

sebma commented Aug 10, 2022

Bug Report

Current Behavior

Hi, I'm trying to display the scoop shim information of the sudo command :

# scoop shim info sudo
Local shim not found: sudo
But a global shim exists, run 'scoop shim info sudo -global' to show its info

This comment suggest us to type the command scoop shim info sudo -global :

# scoop shim info sudo -global
ERROR: Option -global not recognized.
Usage: scoop shim <subcommand> [<shim_names>] [<command_path> [<args>...]] [-g(lobal)]

Expected Behavior

The shim information of sudo is displayed.

Additional context/output

Possible Solution

System details

Windows version: 10 Pro

OS architecture: 64bit

PowerShell version:

# echo $PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  1682

Additional software: [(optional) e.g. ConEmu, Git]

Scoop Configuration

{
    "lastUpdate":  "2022-08-10T17:20:34.7655612+02:00",
    "SCOOP_REPO":  "https://github.com/ScoopInstaller/Scoop",
    "SCOOP_BRANCH":  "master"
}
@sebma sebma added the bug label Aug 10, 2022
@lewis-yeung
Copy link
Contributor

lewis-yeung commented Aug 10, 2022

Related code:

default {
# For 'info' and 'alter'
"ERROR: Option $Args not recognized."
my_usage
exit 1
}

The same error occurs with the subcommand alter. Actually, even for add or rm subcommand, the switch parameter $global doesn't get an expected $true value when you specify the -g/-global flag.

@niheaven Perhaps we can adjust this default case block. How about using getopt to parse arguments rather than the built-in param?

@rashil2000
Copy link
Member

Discussion about avoiding getopt is here: #4736

@lewis-yeung
Copy link
Contributor

lewis-yeung commented Aug 11, 2022

@rashil2000 @niheaven Alternatively, we can make getopt compatible with the GNU extensions to the POSIX conventions for command line options. See The GNU C Library Reference Manual:

The argument -- terminates all options; any following arguments are treated as non-option arguments, even if they begin with a hyphen.

If so, we have to use '--' in PowerShell CLI since the unquoted -- is also the terminator flag in PowerShell syntax, which makes it excluded from $args.

EDITED: We should also change to use the call operator (&) in .cmd -> .ps1 shims and use '--' to pass an exact -- argument in CMD.

@niheaven
Copy link
Member

niheaven commented Aug 11, 2022

Hmm, it's a bug, yes. I'll fix it.

That's strange…… I've tested all the args in that PR.

@niheaven
Copy link
Member

Scoop/lib/commands.ps1

Lines 32 to 36 in 4a31bd3

function exec($cmd, $arguments) {
$cmd_path = command_path $cmd
& $cmd_path @arguments
}

The above function handles parameters and something likes -g is passed as string, and could not be treated as switch...

image

I'm not sure how to fix it (we've discussed that getopt cannot handle param of the shim) 🤣

@lewis-yeung
Copy link
Contributor

lewis-yeung commented Aug 12, 2022

The above function handles parameters and something likes -g is passed as string, and could not be treated as switch...

I noticed this while debugging yesterday. So IMO, we definitely have to give up the current way of parsing arguments in the shim subcommand.

we've discussed that getopt cannot handle param of the shim

Why? If we just introduce the terminator flag -- and tweak the invocation method in .cmd -> .ps1 shims as I mentioned in this comment, it works well with getopt in my test. The only fly in the ointment is that users have to use a quoted version ('--') either in PowerShell or CMD CLI. Another reason I recommend using getopt is that it makes the argument parsing far more consistent with other subcommands.

@niheaven
Copy link
Member

scoop shim add xxxx -g if the shim needs -g as its param.

I'll test -- and find the way.

@lewis-yeung
Copy link
Contributor

scoop shim add xxxx -g if the shim needs -g as its param.

💡 This can also be resolved if the terminator flag -- is introduced.

@lewis-yeung
Copy link
Contributor

@niheaven Anything I can do to help?

@sebma
Copy link
Author

sebma commented Aug 18, 2022

The weird thing is also that scoop info shim sudo does not find the shim for sudo :

# scoop shim info sudo
Local shim not found: sudo
But a global shim exists, run 'scoop shim info sudo -global' to show its info

although it is there :

# (gcm sudo -ShowCommandInfo | Out-String).Trim()
Name          : sudo.exe
ModuleName    :
Module        : @{Name=}
CommandType   : Application
Definition    : C:\ProgramData\scoop\shims\sudo.exe
ParameterSets : {}

@lewis-yeung
Copy link
Contributor

We should also change to use the call operator (&) in .cmd -> .ps1 shims and use '--' to pass an exact -- argument in CMD.

@niheaven Sorry, I made a mistake. 🤦🏻‍♂️ We don't have to change this. Using -- directly in CMD is just fine.

File test.ps1:

$args

File test.cmd:

pwsh -file test.ps1 %*

Run test.cmd arg1 -- arg2 in CMD, output:

arg1
--
arg2

@niheaven
Copy link
Member

Yes, I've found that, and cannot continue 🤣

@lewis-yeung
Copy link
Contributor

Let me try. I'll create PRs for this later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants