Skip to content

Commit

Permalink
read/write cmdline to file
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichael committed Jul 24, 2024
1 parent 5134698 commit ec12167
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/craterstats/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ class SpacedString(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, ' '.join(values))

class LoadFromFile(argparse.Action):
def __call__ (self, parser, namespace, values, option_string = None):
with values as f:
# parse arguments in the file and store them in the target namespace
parser.parse_args(f.read().split(), namespace)
setattr(namespace, self.dest, True)

def get_parser():
parser = argparse.ArgumentParser(description='Craterstats: a tool to analyse and plot crater count data for planetary surface dating.')

parser.add_argument('-i','--input', help="input args from file", type=open, action=LoadFromFile)

parser.add_argument("-lcs", help="list chronology systems", action='store_true')
parser.add_argument("-lpc", help="list plot symbols and colours", action='store_true')
parser.add_argument("-about", help="show program details", action='store_true')
Expand Down Expand Up @@ -303,7 +311,6 @@ def main(args0=None):
demo()
return


cp_dicts = construct_plot_dicts(args, c)
default_filename = '_'.join(sorted(set([gm.filename(d['source'], 'n') for d in cp_dicts])))
cps_dict = construct_cps_dict(args, c, f, default_filename)
Expand All @@ -318,6 +325,9 @@ def main(args0=None):
cps.autoscale(cps_dict['xrange'] if 'xrange' in cps_dict else None,
cps_dict['yrange'] if 'yrange' in cps_dict else None)

if not args.input:
gm.write_textfile(cps_dict['out']+'.cs',' '.join(args0))

drawn=False
for f in cps.format:
if f in {'png','jpg','pdf','svg','tif'}:
Expand Down

0 comments on commit ec12167

Please sign in to comment.