Skip to content

Add Support for Rest/Variadic Arguments #11

@broothie

Description

@broothie

Add Support for Rest/Variadic Arguments

Summary

Implement support for variadic/rest arguments to allow commands to accept an unlimited number of positional arguments.

Background

Many CLI tools need to accept a variable number of arguments (e.g., rm file1 file2 file3..., git add file1 file2...). This feature is already mentioned in the project roadmap and would enable more flexible command patterns.

Requirements

Core Functionality

  • Variadic arguments: Allow commands to accept unlimited positional arguments after required ones
  • Rest argument collection: Collect all remaining arguments into a slice
  • Type safety: Maintain type safety with generic support for different argument types
  • Validation: Ensure rest arguments can be validated and parsed consistently

API Design Considerations

  • Should work with existing argument system
  • Maintain backward compatibility
  • Support for minimum/maximum argument counts
  • Integration with help text generation

Use Cases

// Example: file operations that accept multiple files
myapp copy <source>... <dest>

// Example: command that processes multiple inputs  
myapp process <input>...

// Example: mixed required and variadic args
myapp deploy <environment> <service>...

Implementation Requirements

  • Add variadic argument support to argument parsing
  • Update help text generation to show variadic syntax
  • Ensure type safety with generics
  • Add validation for minimum argument counts
  • Update argument resolution logic
  • Add comprehensive tests

Acceptance Criteria

  • Commands can accept variable numbers of arguments
  • Rest arguments are properly parsed and validated
  • Help text correctly displays variadic argument syntax
  • Type safety is maintained
  • Backward compatibility is preserved
  • Tests cover variadic argument scenarios

Additional Notes

This enhancement would significantly improve the flexibility of the CLI framework and is a common requirement for many CLI applications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions