Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

[Issue] Optional arguments in final array #260

Open
@gtrabanco

Description

@gtrabanco

Describe the bug
Found a bug with optional arguments and final array.

To Reproduce
Define a docopt like this one in a shell script:

#!/usr/bin/env bash
##? Install a package
##?
##? Usage:
##?    $0 [--pkgmgr <package_manager>] <packages_names>...
eval "$(docpars -h "$(grep "^##?" "$0" | cut -c 5-)" : "$@")"
echo "pkgmgr: $pkgmgr"
echo "package_manager: $package_manager"
echo "packages: ${package_names[*]}"
echo

Call the script with arguments:

--pkgmgr cargo docpars deno bashdoc

Show output:

pkgmgr: true
package_manager: cargo
packages: docpars deno bashdoc

Fail 1

All went well, but if you call with arguments:

docpars deno bashdoc

Will show you:

pkgmgr: false
package_manager: docpars
packages: deno bashdoc

The docpars value is in package_manager and not in the final array.

Fail 2

And finally if you call the script with arguments:

--pkgmgr cargo

It will output:

pkgmgr: true
package_manager:
packages: cargo

cargo is in packages_names instead of package_manager.

Expected behavior

Case fail 1

pkgmgr: false
package_manager:
packages: docpars deno bashdoc

Case fail 2

pkgmgr: true
package_manager: cargo
packages: 

Screenshots
Screenshot 2021-07-14 at 16 58 16

Versions:

  • OS: macos 11.4 Big Sur
  • Shell Version [replace this text with the output of sh --version]
> $SHELL --version
zsh 5.8 (x86_64-apple-darwin20.0)
  • docpars: v0.2.0

Additional context
The script is dot package add of my Dotly fork, see it here:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions