Skip to content

Commit

Permalink
Separate positional from optional arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxor1337 committed Mar 24, 2018
1 parent f8321af commit c23d21b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/passff.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,26 @@ def sendMessage(encodedMessage):
if __name__ == "__main__":
# Read message from standard input
receivedMessage = getMessage()
args = []
opt_args = []
pos_args = []
stdin = None

if len(receivedMessage) == 0:
pass
elif receivedMessage[0] == "insert":
args = ["insert", "-m", receivedMessage[1]]
opt_args = ["insert", "-m"]
pos_args = [receivedMessage[1]]
stdin = receivedMessage[2]
elif receivedMessage[0] == "generate":
args = ["generate", receivedMessage[1], receivedMessage[2]]
if "-n" in receivedMessage:
args.append("-n")
pos_args = [receivedMessage[1], receivedMessage[2]]
opt_args = ["generate"]
if "-n" in receivedMessage[3:]:
opt_args.append("-n")
else:
key = receivedMessage[0]
key = "/" + key if key[0] != "/" else key
args.append(key)
key = "/" + (key[1:] if key[0] == "/" else key)
pos_args = [key]
opt_args += commandArgs

# Set up (modified) command environment
env = dict(os.environ)
Expand All @@ -75,7 +79,7 @@ def sendMessage(encodedMessage):
env[key] = val

# Set up subprocess params
cmd = [command] + args + commandArgs
cmd = [command] + opt_args + ['--'] + pos_args
proc_params = {
'stdout': subprocess.PIPE,
'stderr': subprocess.PIPE,
Expand Down

0 comments on commit c23d21b

Please sign in to comment.