9
9
10
10
11
11
import json
12
+ import sys
12
13
13
14
from earthkit .data .utils .dates import to_datetime
14
15
15
16
from ..config import load_config
17
+ from ..inputs .grib import GribInput
16
18
from ..inputs .mars import postproc
17
19
from ..runners .default import DefaultRunner
18
20
from . import Command
@@ -28,7 +30,7 @@ def add_arguments(self, command_parser):
28
30
command_parser .add_argument ("config" , type = str , help = "Path to checkpoint" )
29
31
command_parser .add_argument ("--defaults" , action = "append" , help = "Sources of default values." )
30
32
command_parser .add_argument ("--date" , type = str , help = "Date" )
31
- command_parser .add_argument ("--output" , type = str , help = "Output file" )
33
+ command_parser .add_argument ("--output" , type = str , default = None , help = "Output file" )
32
34
command_parser .add_argument ("--staging-dates" , type = str , help = "Path to a file with staging dates" )
33
35
command_parser .add_argument ("--extra" , action = "append" , help = "Additional request values. Can be repeated" )
34
36
command_parser .add_argument ("--retrieve-fields-type" , type = str , help = "Type of fields to retrieve" )
@@ -60,6 +62,11 @@ def run(self, args):
60
62
61
63
extra = postproc (grid , area )
62
64
65
+ # so that the user does not need to pass --extra target=path when the input file is already in the config
66
+ input = runner .create_input ()
67
+ if isinstance (input , GribInput ):
68
+ extra ["target" ] = input .path
69
+
63
70
for r in args .extra or []:
64
71
k , v = r .split ("=" )
65
72
extra [k ] = v
@@ -83,8 +90,12 @@ def run(self, args):
83
90
r .update (extra )
84
91
requests .append (r )
85
92
86
- with open (args .output , "w" ) as f :
87
- json .dump (requests , f , indent = 4 )
93
+ if args .output and args .output != "-" :
94
+ with open (args .output , "w" ) as f :
95
+ json .dump (requests , f , indent = 4 )
96
+ return
97
+
98
+ json .dump (requests , sys .stdout , indent = 4 )
88
99
89
100
90
101
command = RetrieveCmd
0 commit comments