6
6
from .file_peeking import get_structure
7
7
8
8
9
- def run_from_command ():
10
- parser = argparse .ArgumentParser (
11
- description = "CLI tool for retrieving ROOT file structures."
12
- )
9
+ def make_dataset_list (dataset_arg ):
10
+ """
11
+ Helper to handle the user input daset argument.
12
+ Loads to dict if input is .json else returns default input
13
+ Output is given to get_structure()
13
14
14
- parser .add_argument (
15
- "dataset" ,
16
- nargs = "+" ,
17
- help = "Input datasets (Rucio DID) or a JSON file containing datasets in a dict." ,
18
- )
19
- parser .add_argument (
20
- "--filter-branch" ,
21
- default = "" ,
22
- help = "Only display branches containing this string." ,
23
- )
15
+ Parameters:
16
+ dataset_arg (str, [str]): Single DS identifier, list of multiple identifiers or path/to/.json containig identifiers and sample names.
24
17
25
- args = parser .parse_args ()
26
-
27
- if len (args .dataset ) == 1 and args .dataset [0 ].endswith (".json" ):
28
- dataset_file = args .dataset [0 ]
18
+ Returns:
19
+ dataset (str, [str], dict): dictionary loaded from the json
20
+ """
21
+ if len (dataset_arg ) == 1 and dataset_arg [0 ].endswith (".json" ):
22
+ dataset_file = dataset_arg [0 ]
29
23
30
24
if not os .path .isfile (dataset_file ):
31
25
logging .error (f"Error: JSON file '{ dataset_file } ' not found." )
@@ -46,9 +40,36 @@ def run_from_command():
46
40
sys .exit (1 )
47
41
48
42
else :
49
- # If dataset is provided directly in CLI, use it as a list
50
- dataset = args .dataset
43
+ # If DS is provided in CLI instead of json, use it as a list (default)
44
+ dataset = dataset_arg
45
+
46
+ return dataset
47
+
48
+
49
+ def run_from_command ():
50
+ """
51
+ Calls the get_structure function and sends results to stdout.
52
+ To run on command line: servicex-get-structure -dataset --fileter-branch
53
+ """
54
+ parser = argparse .ArgumentParser (
55
+ description = "CLI tool for retrieving ROOT file structures."
56
+ )
57
+
58
+ parser .add_argument (
59
+ "dataset" ,
60
+ nargs = "+" ,
61
+ help = "Input datasets (Rucio DID) or a JSON file containing datasets in a dict." ,
62
+ )
63
+ parser .add_argument (
64
+ "--filter-branch" ,
65
+ default = "" ,
66
+ help = "Only display branches containing this string." ,
67
+ )
68
+
69
+ args = parser .parse_args ()
70
+
71
+ ds_format = make_dataset_list (args .dataset )
51
72
52
- result = get_structure (dataset , filter_branch = args .filter_branch , do_print = False )
73
+ result = get_structure (ds_format , filter_branch = args .filter_branch , do_print = False )
53
74
54
75
print (result )
0 commit comments