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

cli: fix default flags when their command equivalents are disabled #21469

Merged
merged 5 commits into from
May 8, 2024

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented May 8, 2024

Fixes default flags not working as expected when their commands are disabled.

Example:

// foo.v
import cli { Command, CommandFlag }
import os

fn main() {
	mut cmd := Command{
		name: 'foo'
		version: '0.1.0'
		posix_mode: true
		defaults: struct {
			version: CommandFlag{false, true}
			help: CommandFlag{false, true}
		}
	}
	cmd.parse(os.args)
}

Current:

❯ v run foo.v --version
# no output

Updated:

❯ v run foo.v --version
foo version 0.1.0

@ttytm ttytm marked this pull request as draft May 8, 2024 08:11
@ttytm ttytm force-pushed the cli/default-flag-fix branch 3 times, most recently from 62b8785 to 0e3a4d7 Compare May 8, 2024 08:28
fn version_func(version_cmd Command) ! {
cmd := version_cmd.parent
version := '${cmd.name} version ${cmd.version}'
fn print_version_for_command(cmd Command) ! {
Copy link
Member Author

@ttytm ttytm May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is based on the other default commands execute functions

pub fn print_help_for_command(help_cmd Command) ! {

@ttytm ttytm marked this pull request as ready for review May 8, 2024 08:49
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit c0fec31 into vlang:master May 8, 2024
57 checks passed
@ttytm ttytm deleted the cli/default-flag-fix branch May 8, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants