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:
Casey Rodarmor 2020-03-14 21:41:57 -07:00 committed by GitHub
parent 1dbc765390
commit 784232e98b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 5 deletions

View File

@ -1,4 +1,3 @@
edit:completion:arg-completer[just] = [@words]{ edit:completion:arg-completer[just] = [@words]{
fn spaces [n]{ fn spaces [n]{
repeat $n ' ' | joins '' repeat $n ' ' | joins ''

View File

@ -1,4 +1,3 @@
using namespace System.Management.Automation using namespace System.Management.Automation
using namespace System.Management.Automation.Language using namespace System.Management.Automation.Language

View File

@ -60,4 +60,4 @@ _just_commands() {
_describe -t commands 'just commands' commands "$@" _describe -t commands 'just commands' commands "$@"
} }
_just "$@" _just "$@"

View File

@ -6,7 +6,7 @@ pub(crate) use std::{
env, env,
fmt::{self, Debug, Display, Formatter}, fmt::{self, Debug, Display, Formatter},
fs, fs,
io::{self, Write}, io::{self, Cursor, Write},
iter::{self, FromIterator}, iter::{self, FromIterator},
ops::{Index, Range, RangeInclusive}, ops::{Index, Range, RangeInclusive},
path::{Path, PathBuf}, path::{Path, PathBuf},

View File

@ -464,7 +464,12 @@ impl Config {
.parse::<clap::Shell>() .parse::<clap::Shell>()
.expect("Invalid value for 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(()) Ok(())
} }