1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-10-31 19:42:16 +01:00

Improve help of the 'git-obs login' subcommands

This commit is contained in:
2025-04-17 16:21:36 +02:00
parent 4f1d92f844
commit 4b10e0381e
5 changed files with 82 additions and 82 deletions

View File

@@ -5,21 +5,21 @@ Background:
When I execute git-obs with args "login list"
Then stdout is
"""
Name : admin
Default : true
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Admin
SSH Key : {context.fixtures}/ssh-keys/admin
Name : admin
Default : true
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Admin
Private SSH key path : {context.fixtures}/ssh-keys/admin
Name : alice
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Alice
SSH Key : {context.fixtures}/ssh-keys/alice
Name : alice
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Alice
Private SSH key path : {context.fixtures}/ssh-keys/alice
Name : bob
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Bob
SSH Key : {context.fixtures}/ssh-keys/bob
Name : bob
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Bob
Private SSH key path : {context.fixtures}/ssh-keys/bob
"""
@@ -34,33 +34,33 @@ Scenario: Add a credentials login entry
And stdout is
"""
Added entry:
Name : example1
Default : true
URL : https://gitea.example.com
User : Admin
Name : example1
Default : true
URL : https://gitea.example.com
User : Admin
"""
When I execute git-obs with args "login list"
Then stdout is
"""
Name : admin
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Admin
SSH Key : {context.fixtures}/ssh-keys/admin
Name : admin
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Admin
Private SSH key path : {context.fixtures}/ssh-keys/admin
Name : alice
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Alice
SSH Key : {context.fixtures}/ssh-keys/alice
Name : alice
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Alice
Private SSH key path : {context.fixtures}/ssh-keys/alice
Name : bob
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Bob
SSH Key : {context.fixtures}/ssh-keys/bob
Name : bob
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Bob
Private SSH key path : {context.fixtures}/ssh-keys/bob
Name : example1
Default : true
URL : https://gitea.example.com
User : Admin
Name : example1
Default : true
URL : https://gitea.example.com
User : Admin
"""
@@ -75,24 +75,24 @@ Scenario: Remove a credentials login entry
And stdout is
"""
Removed entry:
Name : admin
Default : true
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Admin
SSH Key : {context.fixtures}/ssh-keys/admin
Name : admin
Default : true
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Admin
Private SSH key path : {context.fixtures}/ssh-keys/admin
"""
When I execute git-obs with args "login list"
Then stdout is
"""
Name : alice
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Alice
SSH Key : {context.fixtures}/ssh-keys/alice
Name : alice
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Alice
Private SSH key path : {context.fixtures}/ssh-keys/alice
Name : bob
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Bob
SSH Key : {context.fixtures}/ssh-keys/bob
Name : bob
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Bob
Private SSH key path : {context.fixtures}/ssh-keys/bob
"""
@@ -107,32 +107,32 @@ Scenario: Update a credentials login entry
And stdout is
"""
Original entry:
Name : alice
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Alice
SSH Key : {context.fixtures}/ssh-keys/alice
Name : alice
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Alice
Private SSH key path : {context.fixtures}/ssh-keys/alice
Updated entry:
Name : NEW_NAME
Default : true
URL : NEW_URL
User : NEW_USER
Name : NEW_NAME
Default : true
URL : NEW_URL
User : NEW_USER
"""
When I execute git-obs with args "login list"
Then stdout is
"""
Name : admin
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Admin
SSH Key : {context.fixtures}/ssh-keys/admin
Name : admin
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Admin
Private SSH key path : {context.fixtures}/ssh-keys/admin
Name : NEW_NAME
Default : true
URL : NEW_URL
User : NEW_USER
Name : NEW_NAME
Default : true
URL : NEW_URL
User : NEW_USER
Name : bob
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Bob
SSH Key : {context.fixtures}/ssh-keys/bob
Name : bob
URL : http://localhost:{context.podman.container.ports[gitea_http]}
User : Bob
Private SSH key path : {context.fixtures}/ssh-keys/bob
"""

View File

@@ -15,12 +15,12 @@ class LoginAddCommand(osc.commandline_git.GitObsCommand):
def init_arguments(self):
from osc.commandline_git import complete_ssh_key_path
self.parser.add_argument("name")
self.parser.add_argument("--url", required=True)
self.parser.add_argument("--user", required=True)
self.parser.add_argument("--token", help="Omit or set to '-' to invoke a secure interactive prompt.")
self.parser.add_argument("--ssh-key").completer = complete_ssh_key_path
self.parser.add_argument("--set-as-default", action="store_true", default=None)
self.parser.add_argument("name", help="The name of the login entry to be added")
self.parser.add_argument("--url", help="Gitea URL, for example https://example.com", required=True)
self.parser.add_argument("--user", help="Gitea username", required=True)
self.parser.add_argument("--token", help="Gitea access token; omit or set to '-' to invoke a secure interactive prompt")
self.parser.add_argument("--ssh-key", metavar="PATH", help="Path to a private SSH key").completer = complete_ssh_key_path
self.parser.add_argument("--set-as-default", help="Set the new login entry as default", action="store_true", default=None)
def run(self, args):
from osc import gitea_api

View File

@@ -14,7 +14,7 @@ class LoginRemoveCommand(osc.commandline_git.GitObsCommand):
def init_arguments(self):
from osc.commandline_git import complete_login
self.parser.add_argument("name").completer = complete_login
self.parser.add_argument("name", help="The name of the login entry to be removed").completer = complete_login
def run(self, args):
print(f"Removing a Gitea credentials entry with name '{args.name}' ...", file=sys.stderr)

View File

@@ -15,13 +15,13 @@ class LoginUpdateCommand(osc.commandline_git.GitObsCommand):
def init_arguments(self):
from osc.commandline_git import complete_ssh_key_path
self.parser.add_argument("name")
self.parser.add_argument("--new-name")
self.parser.add_argument("--new-url")
self.parser.add_argument("--new-user")
self.parser.add_argument("--new-token", help="Set to '-' to invoke a secure interactive prompt.")
self.parser.add_argument("--new-ssh-key").completer = complete_ssh_key_path
self.parser.add_argument("--set-as-default", action="store_true")
self.parser.add_argument("name", help="The name of the login entry to be updated")
self.parser.add_argument("--new-name", help="New name of the login entry")
self.parser.add_argument("--new-url", metavar="URL", help="New Gitea URL, for example https://example.com",)
self.parser.add_argument("--new-user", metavar="USER", help="Gitea username")
self.parser.add_argument("--new-token", metavar="TOKEN", help="Gitea access token; set to '-' to invoke a secure interactive prompt")
self.parser.add_argument("--new-ssh-key", metavar="PATH", help="Path to a private SSH key").completer = complete_ssh_key_path
self.parser.add_argument("--set-as-default", action="store_true", help="Set the login entry as default")
def run(self, args):
print(f"Updating a Gitea credentials entry with name '{args.name}' ...", file=sys.stderr)

View File

@@ -53,14 +53,14 @@ class Login(BaseModel):
def to_human_readable_string(self, *, show_token: bool = False):
from osc.output import KeyValueTable
table = KeyValueTable()
table = KeyValueTable(min_key_length=20)
table.add("Name", self.name, color="bold")
if self.default:
table.add("Default", "true", color="bold")
table.add("URL", self.url)
table.add("User", self.user)
if self.ssh_key:
table.add("SSH Key", self.ssh_key)
table.add("Private SSH key path", self.ssh_key)
if show_token:
# tokens are stored in the plain text, there's not reason to protect them too much
# let's only hide them from the output by default