Skip to content

Commit

Permalink
parser for CLI #927
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkobrombin committed Mar 27, 2022
1 parent fe2fc94 commit c11e040
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/cli.in
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ class CLI:
new_parser.add_argument("--nvapi", help="Name of the dxvk-nvapi to be used")
new_parser.add_argument("--latencyflex", help="Name of the latencyflex to be used")

run_parser = subparsers.add_parser("run", help="Run a program")
run_parser.add_argument("-b", "--bottle", help="Bottle name", required=True)
run_parser.add_argument("-e", "--executable", help="Path to the executable")
run_parser.add_argument("-a", "--args", help="Arguments to pass to the executable")
run_parser.add_argument("-p", "--program", help="Program to run")

self.__process_args()

@staticmethod
Expand Down Expand Up @@ -163,6 +169,10 @@ class CLI:
elif self.args.command == "new":
self.new_bottle()

# RUN parser
elif self.args.command == "run":
self.run_program()

# region INFO
def show_info(self):
_type = self.args.type
Expand Down Expand Up @@ -436,6 +446,46 @@ class CLI:

# endregion

# region RUN
def run_program(self):
_bottle = self.args.bottle
_program = self.args.program
_args = "" if self.args.args is None else self.args.args
_executable = self.args.executable
_cwd = None
mng = Manager(self, is_cli=True)
mng.checks()

if _bottle not in mng.local_bottles:
sys.stderr.write(f"Bottle {_bottle} not found\n")
exit(1)

bottle = mng.local_bottles[_bottle]
programs = mng.get_programs(bottle)

if _program is not None:
if _executable is not None:
sys.stderr.write(f"Cannot specify both --program and --executable\n")
exit(1)

if _program not in [p["name"] for p in programs]:
sys.stderr.write(f"Program {_program} not found\n")
exit(1)

program = [p for p in programs if p["name"] == _program][0]
_executable = program.get("path", "")
_args = program.get("arguments", "")
_cwd = program.get("folder", "")

WineExecutor(
bottle,
exec_path=_executable,
args=_args,
cwd=_cwd,
).run_cli()

# endregion


if __name__ == '__main__':
cli = CLI()

0 comments on commit c11e040

Please sign in to comment.