Trim completions and ensure final newline (#609)
Trim whitespace at beginning and end of generated completions. Additionally, since some editors will automatically insert a final newline into text files, make sure a final newline is present.
This commit is contained in:
parent
1dbc765390
commit
784232e98b
@ -1,4 +1,3 @@
|
||||
|
||||
edit:completion:arg-completer[just] = [@words]{
|
||||
fn spaces [n]{
|
||||
repeat $n ' ' | joins ''
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
using namespace System.Management.Automation
|
||||
using namespace System.Management.Automation.Language
|
||||
|
||||
|
@ -60,4 +60,4 @@ _just_commands() {
|
||||
_describe -t commands 'just commands' commands "$@"
|
||||
}
|
||||
|
||||
_just "$@"
|
||||
_just "$@"
|
||||
|
@ -6,7 +6,7 @@ pub(crate) use std::{
|
||||
env,
|
||||
fmt::{self, Debug, Display, Formatter},
|
||||
fs,
|
||||
io::{self, Write},
|
||||
io::{self, Cursor, Write},
|
||||
iter::{self, FromIterator},
|
||||
ops::{Index, Range, RangeInclusive},
|
||||
path::{Path, PathBuf},
|
||||
|
@ -464,7 +464,12 @@ impl Config {
|
||||
.parse::<clap::Shell>()
|
||||
.expect("Invalid value for clap::Shell");
|
||||
|
||||
Self::app().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut io::stdout());
|
||||
let buffer = Vec::new();
|
||||
let mut cursor = Cursor::new(buffer);
|
||||
Self::app().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut cursor);
|
||||
let buffer = cursor.into_inner();
|
||||
let text = String::from_utf8(buffer).expect("Clap completion not UTF-8");
|
||||
println!("{}", text.trim());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user