Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Command Line Tool -> Select with arrow keys and spacebar

I'm building command line tools with swift and I'd like to make them more interactive to provide a better user experience.

I was wondering if it's possible to build a select menu for a command line tool similar to the one used in the firebase cli or the angular cli in swift. I'm using the swift argument parser at the moment and it would be very nice if the user could select from different options in a menu via the arrow keys and selecting with the space bar.

Firebase CLI option selection with firebase init

like image 821
Valentin Hartig Avatar asked Dec 01 '25 23:12

Valentin Hartig


1 Answers

As far as I know, this is not possible with swift-argument-parser at this monent. This was actually in the Summer of Code idea list for potential projects.

Swift ArgumentParser: Interactive mode

ArgumentParser provides a straightforward way to declare command-line interfaces in Swift, with the dual goals of making it (1) fast and easy to create (2) high-quality, user-friendly CLI tools. For this project, we would design and implement an interactive mode for tools built using ArgumentParser that prompts for any required arguments not given in the initial command. This work would need to allow partial initialization of types, and could include features like validation and auto-completion for user input.

https://www.swift.org/gsoc2021/

So I believe it might be implemented in the future.

like image 131
Kotaro Suto Avatar answered Dec 04 '25 17:12

Kotaro Suto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!