From 784232e98b835e0ae7a86450a5236a0a37ebddee Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 14 Mar 2020 21:41:57 -0700 Subject: [PATCH] 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. --- completions/just.elvish | 1 - completions/just.powershell | 1 - completions/just.zsh | 2 +- src/common.rs | 2 +- src/config.rs | 7 ++++++- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/completions/just.elvish b/completions/just.elvish index 90f9b03..b1b128c 100644 --- a/completions/just.elvish +++ b/completions/just.elvish @@ -1,4 +1,3 @@ - edit:completion:arg-completer[just] = [@words]{ fn spaces [n]{ repeat $n ' ' | joins '' diff --git a/completions/just.powershell b/completions/just.powershell index ed79006..9f92c24 100644 --- a/completions/just.powershell +++ b/completions/just.powershell @@ -1,4 +1,3 @@ - using namespace System.Management.Automation using namespace System.Management.Automation.Language diff --git a/completions/just.zsh b/completions/just.zsh index 3f5aed2..4724fa8 100644 --- a/completions/just.zsh +++ b/completions/just.zsh @@ -60,4 +60,4 @@ _just_commands() { _describe -t commands 'just commands' commands "$@" } -_just "$@" \ No newline at end of file +_just "$@" diff --git a/src/common.rs b/src/common.rs index 33a2359..80201dd 100644 --- a/src/common.rs +++ b/src/common.rs @@ -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}, diff --git a/src/config.rs b/src/config.rs index a413754..fdda02f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -464,7 +464,12 @@ impl Config { .parse::() .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(()) }