2020
2121"""
2222
23+ import argparse
24+ import json
2325import logging
2426import math
2527import os
2628import sys
2729
2830import commonl
31+ import tcfl .ui_cli
2932
3033logger = logging .getLogger ("ui_cli_testcases" )
3134
3235
33-
3436def _cmdline_targets_init (args ):
3537 # initialize reporting based on what the commandline wants
3638
@@ -51,6 +53,24 @@ def _cmdline_targets_init(args):
5153
5254
5355
56+ def _cmdline_target_get (cli_args : argparse .Namespace ):
57+
58+ def _target_get (target , _cli_args ):
59+ projections = cli_args .project
60+ server = tcfl .server_c .servers [target .rt ['server' ]]
61+ rt = server .targets_get (target_id = target .id ,
62+ projections = cli_args .project )
63+ # rt is a list of dicts keyed by fullid, we care only for the first
64+ json .dump (rt [0 ][target .fullid ], sys .stdout , indent = 4 )
65+
66+ return tcfl .ui_cli .run_fn_on_each_targetspec (
67+ # note we scan ignoring --projections, since that we'll use
68+ # later; we want to identify the target to get as soon as
69+ # possible and then in _target_get() we do the stuff
70+ _target_get , cli_args , only_one = True )
71+
72+
73+
5474def _targets_list_v0_table (l ):
5575
5676 if not l : # avoid divide by zero errors
@@ -211,3 +231,19 @@ def _cmdline_setup(arg_subparsers):
211231 help = "consider only the given fields "
212232 "(default depends on verbosity" )
213233 ap .set_defaults (func = _cmdline_ls )
234+
235+
236+
237+ def _cmdline_setup_advanced (arg_subparsers ):
238+ ap = arg_subparsers .add_parser (
239+ "get" , help = "Return target information straight from the "
240+ "server formated as JSON (unlike 'ls', which will add some "
241+ "client fields)" )
242+ tcfl .ui_cli .args_verbosity_add (ap )
243+ tcfl .ui_cli .args_targetspec_add (ap , targetspec_n = 1 )
244+ ap .add_argument (
245+ "-p" , "--project" , "--projection" , metavar = "FIELD" ,
246+ action = "append" , type = str ,
247+ help = "consider only the given fields "
248+ "(default depends on verbosity" )
249+ ap .set_defaults (func = _cmdline_target_get )
0 commit comments