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

No file paths for flag.new_flag_parser(os.args).string() possible #19996

Open
PetFeld opened this issue Nov 25, 2023 · 0 comments
Open

No file paths for flag.new_flag_parser(os.args).string() possible #19996

PetFeld opened this issue Nov 25, 2023 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@PetFeld
Copy link

PetFeld commented Nov 25, 2023

Describe the bug

Code: https://gist.github.com/PetFeld/92a83032db14a080ae8a2fa419660d91

#!/usr/bin/env -S v

import os
import flag

fn main() {
	mut fp := flag.new_flag_parser(os.args)

	fp.application('flag_parser_example')
	fp.version('0.0.1')
	fp.description('Example V shell script')
	fp.skip_executable()

	file_path := fp.string('path', `p`, '', 'The path to the file to read')

	fp.finalize()!

	println('File path: ${file_path}')
}

Saving the script as flag_parser_example.vsh and running it with ./flag_parser_example.sh --path /etc/bash.bashrc or any other existing file path does not execute the script as expected but gives the message Too many targets. Specify just one target: <target.v|target_directory>..

Reproduction Steps

  • Save the above script
  • Run it with ./<script_name>.vsh --path <existing file path>

You will see the script is not executed but instead the message Too many targets. Specify just one target: <target.v|target_directory>. appears.

Expected Behavior

The script should print File path: /etc/bash.bashrc if it was called with --path /etc/bash.bashrc.

It behaves as expected for any random string or any string formatted like a file pointing to a non-existent file path, e.g. ./flag_parser_example.vsh --path /etc/bash.nonexistent prints File path: /etc/bash.nonexistent as one would expect.

Current Behavior

Running the script wit --path <path to existing file> prints Too many targets. Specify just one target: <target.v|target_directory>. instead of running the script with the behaviour explained above.

Running v run flag_parser_example.vsh --path /etc/bash.bashrc behaves as expected and prints File path: /etc/bash.bashrc.

Possible Solution

No response

Additional Information/Context

This behaviour prevents from writing useful scripts in V instead of Bash as it is very often necessary to have file paths to existing files as input.

V version

V 0.4.3 e1a474e

Environment details (OS name and version, etc.)

V full version: V 0.4.3 e1a474e
OS: linux, Ubuntu 20.04.6 LTS (WSL 2)
Processor: 12 cpus, 64bit, little endian, Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz

getwd: /home/tyr/projects/tests/v-cli
vexe: /home/tyr/v/v
vexe mtime: 2023-11-25 19:06:38

vroot: OK, value: /home/tyr/v
VMODULES: OK, value: /home/tyr/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.25.1
Git vroot status: weekly.2023.42-331-ge1a474e1
.git/config present: true

CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@PetFeld PetFeld added the Bug This tag is applied to issues which reports bugs. label Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant