israel-lugo / netcalc

Advanced network calculator and address planning helper
GNU General Public License v3.0
21 stars 0 forks source link

Accept network arguments from file #2

Closed israel-lugo closed 8 years ago

israel-lugo commented 8 years ago

New option to specify networks from file. Ideally, this should work with a consistent syntax for all commands. One idea would be to have to have a global option that tells netcalc to read args from the file. Something like:

$ netcalc --arg-file networks.txt add

Where networks.txt is a list of networks, one per line:

198.18.0.0/24
198.18.1.0/24
10.1/16
10/16

Or, for the expr command, which has a more complex syntax:

$ netcalc --arg-file expr.txt expr

Where expr.txt contains:

2001:db8::/34
-
2001:db8::/38
+
2001:db8:100::/41
israel-lugo commented 8 years ago

It would be nice to accept networks from other formats. Jason Iannone asked by email to have "other inputs, including common open ipams, flat texts, MySQL, and radb, or CIDR report integration".

We need to consider how to integrate these formats with the arbitrary syntax of expr. Perhaps these could just be accepted by the simpler add and sub commands, which merely take a list of networks.

Support for this will be tracked in a new ticket.

israel-lugo commented 8 years ago

It turns out that, with the way we're parsing the command arguments right now, it's not trivial to switch from command-line parsing to file parsing mid command. This would be easier if we implement our own parser for the command args, instead of relying on Python's argparse.

For now, it would be much easier to implement something in the following scheme:

$ netcalc add @networks.txt

Where the contents of networks.txt are expanded in-place as though they had been typed on the command-line.