Skip to content

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

Merged
spytheman merged 5 commits into
vlang:masterfrom
ttytm:cli/default-flag-fix
May 8, 2024
Merged

spytheman merged 5 commits into
vlang:masterfrom
ttytm:cli/default-flag-fix

Conversation

@ttytm

@ttytm ttytm commented May 8, 2024

Copy link
Copy Markdown
Member

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
Comment thread vlib/cli/version.v
fn version_func(version_cmd Command) ! {
cmd := version_cmd.parent
version := '${cmd.name} version ${cmd.version}'
fn print_version_for_command(cmd Command) ! {

@ttytm ttytm May 8, 2024 •

Copy link
Copy Markdown
Member Author

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
@ttytm
ttytm force-pushed the cli/default-flag-fix branch from 5abdf32 to fad69a1 Compare May 8, 2024 08:53
@ttytm
ttytm force-pushed the cli/default-flag-fix branch from fad69a1 to 792d88e Compare May 8, 2024 08:55

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

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
@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.

2 participants