]>
git.proxmox.com Git - rustc.git/blob - vendor/clap_complete/src/dynamic/shells/shell.rs
4 use clap
::builder
::PossibleValue
;
7 /// Shell with auto-generated completion script available.
8 #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
11 /// Bourne Again SHell (bash)
13 /// Friendly Interactive SHell (fish)
17 impl Display
for Shell
{
18 fn fmt(&self, f
: &mut std
::fmt
::Formatter
<'_
>) -> std
::fmt
::Result
{
19 self.to_possible_value()
20 .expect("no values are skipped")
26 impl FromStr
for Shell
{
29 fn from_str(s
: &str) -> Result
<Self, Self::Err
> {
30 for variant
in Self::value_variants() {
31 if variant
.to_possible_value().unwrap().matches(s
, false) {
35 Err(format
!("invalid variant: {s}"))
39 // Hand-rolled so it can work even when `derive` feature is disabled
40 impl ValueEnum
for Shell
{
41 fn value_variants
<'a
>() -> &'a
[Self] {
42 &[Shell
::Bash
, Shell
::Fish
]
45 fn to_possible_value
<'a
>(&self) -> Option
<PossibleValue
> {
47 Shell
::Bash
=> PossibleValue
::new("bash"),
48 Shell
::Fish
=> PossibleValue
::new("fish"),
54 fn completer(&self) -> &dyn crate::dynamic
::Completer
{
56 Self::Bash
=> &super::Bash
,
57 Self::Fish
=> &super::Fish
,
62 impl crate::dynamic
::Completer
for Shell
{
63 fn file_name(&self, name
: &str) -> String
{
64 self.completer().file_name(name
)
66 fn write_registration(
71 buf
: &mut dyn std
::io
::Write
,
72 ) -> Result
<(), std
::io
::Error
> {
74 .write_registration(name
, bin
, completer
, buf
)
78 cmd
: &mut clap
::Command
,
79 args
: Vec
<std
::ffi
::OsString
>,
80 current_dir
: Option
<&std
::path
::Path
>,
81 buf
: &mut dyn std
::io
::Write
,
82 ) -> Result
<(), std
::io
::Error
> {
83 self.completer().write_complete(cmd
, args
, current_dir
, buf
)