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

This commit is contained in:
Ryan Petrello
2019-09-01 08:17:07 -04:00
parent 45f9457abe
commit 4ec5e82023
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
@@ -44,8 +46,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.'
@@ -154,7 +163,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'