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

Plugin-API Command:args(args) parses given arguments as positional arguments inside quotes #1711

Closed
ysooqe opened this issue Oct 1, 2024 · 1 comment
Labels
invalid This doesn't seem right

Comments

@ysooqe
Copy link

ysooqe commented Oct 1, 2024

What system are you running Yazi on?

Linux Wayland

What terminal are you running Yazi in?

foot version: 1.18.1 +pgo +ime +graphemes -assertions

yazi --debug output

Yazi
    Version: 0.3.3 (40211df 2024-10-01)
    Debug  : false
    OS     : linux-x86_64 (unix)

Ya
    Version: 0.3.3 (Arch Linux 2024-09-05)

Emulator
    Emulator.via_env: ("foot-extra", "")
    Emulator.via_csi: Ok(Foot)
    Emulator.detect : Foot

Adapter
    Adapter.matches: Sixel

Desktop
    XDG_SESSION_TYPE           : Some("wayland")
    WAYLAND_DISPLAY            : Some("wayland-1")
    DISPLAY                    : Some(":0")
    SWAYSOCK                   : Some("/run/user/1000/sway-ipc.1000.1204.sock")
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

Variables
    SHELL              : Some("/bin/bash")
    EDITOR             : Some("helix")
    VISUAL             : Some("helix")
    YAZI_FILE_ONE      : None
    YAZI_CONFIG_HOME   : None

Text Opener
    default: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block  : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : No such file or directory (os error 2)
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file             : 5.45
    ueberzugpp       : No such file or directory (os error 2)
    ffmpegthumbnailer: No such file or directory (os error 2)
    magick           : 7.1.1-38
    fzf              : 0.55.0
    fd               : 10.2.0
    rg               : 14.1.1
    chafa            : No such file or directory (os error 2)
    zoxide           : No such file or directory (os error 2)
    7z               : 17.05
    7zz              : No such file or directory (os error 2)
    jq               : 1.7.1


--------------------------------------------------

Did you try the latest nightly build to see if the problem got fixed?

Yes, and I updated the debug information above (yazi --debug) to the nightly that I tried

Describe the bug

When I try to pass arguments to a command that is called via the plugin-API Command:args(args), the arguments are passed to the command as positional arguments, not as named arguments.

Example:
Calling Command("fd"):args({ "--type d" }):output() results in an error, because the command that is executed is fd "--type d" instead of fd --type d (notice the quotation marks in both examples).
For some commands this might work fine since they seem to be able to parse positional arguments as named arguments aswell, for example ls -l and ls "-l" both run fine, but there are some commands, like fd, which are not able to do that.
(Note: fd is just used as an example here, I know that there is an inbuilt fd but this is not relevant for this issue).

Minimal reproducer

-- ~/.config/yazi/test.yazi/init.lua
return {
  entry = function()
    local fd =
      Command("fd")
        :args({ "--type d" })
        :output()
  	ya.notify { title = "fd error", content = fd.stderr, timeout = 5, level = "error" }
  end
}

then call the plugin by using a keybinding in keymap.toml:

[manager]
prepend_keymap = [
        { on = "t", run = "plugin test", desc = "Test" },
]

Anything else?

No response

@ysooqe ysooqe added the bug Something isn't working label Oct 1, 2024
@sxyazi
Copy link
Owner

sxyazi commented Oct 1, 2024

This is expected behavior. Yazi's Command API is a wrapper of Rust's Command, so it follows Rust's parameter conventions.

You should use args({ "--type", "d" }) instead of args({ "--type d" }). You can see more examples at https://doc.rust-lang.org/std/process/struct.Command.html#method.args.

@sxyazi sxyazi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 1, 2024
@sxyazi sxyazi added invalid This doesn't seem right and removed bug Something isn't working labels Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants