From 642d27f45711f86092ed7512f7fd02bae75e31ab Mon Sep 17 00:00:00 2001 From: Wil Cooley Date: Wed, 18 Oct 2023 17:08:40 -0700 Subject: [PATCH 1/2] Add argument to not output newline with "get" While this could be more sophisticated (such as supporting a `--newline` for symmetry, to undo the effect of a prior `--no-newline`), this is enough to get started and for my own personal needs. --- keyring/cli.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/keyring/cli.py b/keyring/cli.py index a9612bab..da319cae 100755 --- a/keyring/cli.py +++ b/keyring/cli.py @@ -37,6 +37,12 @@ def __init__(self): self.parser.add_argument( "--disable", action="store_true", help="Disable keyring and exit" ) + self.parser.add_argument( + "--no-newline", + action="store_false", + default=True, + dest="include_newline", + help="Exclude newline from 'get' output") self.parser._operations = ["get", "set", "del", "diagnose"] self.parser.add_argument( 'operation', @@ -84,7 +90,8 @@ def do_get(self): password = get_password(self.service, self.username) if password is None: raise SystemExit(1) - print(password) + end = None if self.include_newline else "" + print(password, end=end) def do_set(self): password = self.input_password( From 8e4e88552bbdcc1c797f97be5e8853d870d22aa2 Mon Sep 17 00:00:00 2001 From: Wil Cooley Date: Mon, 23 Oct 2023 10:00:46 -0700 Subject: [PATCH 2/2] Fix formatting per black --- keyring/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/keyring/cli.py b/keyring/cli.py index da319cae..76368c25 100755 --- a/keyring/cli.py +++ b/keyring/cli.py @@ -42,7 +42,8 @@ def __init__(self): action="store_false", default=True, dest="include_newline", - help="Exclude newline from 'get' output") + help="Exclude newline from 'get' output", + ) self.parser._operations = ["get", "set", "del", "diagnose"] self.parser.add_argument( 'operation',