Skip to content

Commit

Permalink
nexus: improve options user interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkrogel committed Dec 16, 2024
1 parent 28aabbc commit acf9484
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 36 deletions.
26 changes: 1 addition & 25 deletions nexus/lib/machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,7 @@ def read(self,options):
self[str(len(self))] = o
#end for
elif isinstance(options,str):
nopts = 0
intext = False
nstart = -2
nend = -2
n = 0
for c in options:
if c=='-' and nstart!=n-1 and not intext:
prevdash=True
if nopts>0:
opt = options[nstart:n].strip()
name = opt.replace('-','').replace('=',' ').split()[0]
self[name]=opt
#end if
nopts+=1
nstart = n
elif c=='"' or c=="'":
intext=not intext
#end if
n+=1
#end for
if nopts>0:
opt = options[nstart:n].strip()
name = opt.replace('-','').replace('=',' ').split()[0]
self[name]=opt
#end if
self[str(len(self))] = options
else:
self.error('invalid type provided to Options')
#end if
Expand Down
14 changes: 3 additions & 11 deletions nexus/tests/unit/test_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,16 @@ def test_options():

# read
opts = '-a -b 1 -c=2 --dname="0 1 2" --evar -fval -gval other --hval'
ref = obj(
a = '-a',
b = '-b 1',
c = '-c=2',
dname = '--dname="0 1 2"',
evar = '--evar',
fval = '-fval',
gval = '-gval other',
hval = '--hval',
)
ref = obj()
ref['0'] = opts
o = Options()
o.read(opts)
assert(object_eq(o.to_obj(),ref))

# write
opts_write = o.write()
o2 = Options()
o2.read(opts_write)
o2.read(opts_write.strip())
assert(object_eq(o2.to_obj(),ref))
#end def test_options

Expand Down

0 comments on commit acf9484

Please sign in to comment.