Merge pull request #4640 from ryanpetrello/cli-lookup-by-name

cli: add ability to specify a name instead of primary key

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2019-09-03 22:09:10 +00:00
committed by GitHub
7 changed files with 120 additions and 29 deletions

View File

@@ -1,3 +1,5 @@
import functools
from six import with_metaclass
from .stdout import monitor, monitor_workflow
@@ -45,8 +47,15 @@ class CustomAction(with_metaclass(CustomActionRegistryMeta)):
class Launchable(object):
def add_arguments(self, parser, with_pk=True):
from .options import pk_or_name
if with_pk:
parser.choices[self.action].add_argument('id', type=int, help='')
parser.choices[self.action].add_argument(
'id',
type=functools.partial(
pk_or_name, None, self.resource, page=self.page
),
help=''
)
parser.choices[self.action].add_argument(
'--monitor', action='store_true',
help='If set, prints stdout of the launched job until it finishes.'
@@ -155,7 +164,14 @@ class HasStdout(object):
action = 'stdout'
def add_arguments(self, parser):
parser.choices['stdout'].add_argument('id', type=int, help='')
from .options import pk_or_name
parser.choices['stdout'].add_argument(
'id',
type=functools.partial(
pk_or_name, None, self.resource, page=self.page
),
help=''
)
def perform(self):
fmt = 'txt_download'