Add subcommand for printing comment area
This commit is contained in:
parent
6b2207a345
commit
b5f23ddbe2
|
@ -1,3 +1,4 @@
|
|||
from sys import argv, exit
|
||||
import sys
|
||||
from .commandline import main
|
||||
exit(main(argv[1:]) or 0)
|
||||
sys.stdout.write(main(sys.argv[1:]))
|
||||
sys.exit(0)
|
||||
|
|
|
@ -14,6 +14,13 @@ def main(args):
|
|||
)
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
p = subparsers.add_parser(
|
||||
'comment',
|
||||
help="Print a file's comment blocks",
|
||||
)
|
||||
p.set_defaults(func=comment)
|
||||
p.add_argument('path', help='Path to a SPICE file')
|
||||
|
||||
p = subparsers.add_parser(
|
||||
'daf',
|
||||
help="List a file's raw segment descriptors",
|
||||
|
@ -44,9 +51,15 @@ def main(args):
|
|||
sys.exit(2)
|
||||
|
||||
lines = list(func(args))
|
||||
lines.append('')
|
||||
if lines and not lines[-1].endswith('\n'):
|
||||
lines.append('')
|
||||
return '\n'.join(lines)
|
||||
|
||||
def comment(args):
|
||||
with open(args.path, 'rb') as f:
|
||||
d = DAF(f)
|
||||
yield d.comments()
|
||||
|
||||
def daf_segments(args):
|
||||
with open(args.path, 'rb') as f:
|
||||
d = DAF(f)
|
||||
|
|
|
@ -377,6 +377,11 @@ class NAIF_DAF_Tests(TestCase):
|
|||
class CommandLineTests(TestCase):
|
||||
maxDiff = 9999
|
||||
|
||||
def test_comment_command(self):
|
||||
output = commandline.main(['comment', 'de405.bsp'])
|
||||
self.assertEqual(output[:30], '; de405.bsp LOG FILE\n;\n; Creat')
|
||||
self.assertEqual(output[-30:], "rom Standish's DE405 memo <<<\n")
|
||||
|
||||
def test_daf_command(self):
|
||||
self.assertEqual(commandline.main(['daf', 'de405.bsp']), """\
|
||||
1 DE-405 -1577879958.8160586 1577880064.1839132 1 0 1 2 1409 202316
|
||||
|
|
Loading…
Reference in New Issue