-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathforge.py
More file actions
47 lines (35 loc) · 1.24 KB
/
forge.py
File metadata and controls
47 lines (35 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
import argparse
from forge.cli.download import Download
from forge.cli.run import Run
class ForgeCLIParser:
"""Holds all information related to running the CLI"""
def __init__(self):
# Initialize the top-level parser
self._parser = argparse.ArgumentParser(
prog="forge",
description="Welcome to the torchforge CLI!",
add_help=True,
)
# Default command is to print help
self._parser.set_defaults(func=lambda args: self._parser.print_help())
# Add subcommands
subparsers = self._parser.add_subparsers(title="subcommands")
Download.create(subparsers)
Run.create(subparsers)
def parse_args(self) -> argparse.Namespace:
"""Parse CLI arguments"""
return self._parser.parse_args()
def run(self, args: argparse.Namespace) -> None:
"""Execute CLI"""
args.func(args)
def main():
parser = ForgeCLIParser()
args = parser.parse_args()
parser.run(args)
if __name__ == "__main__":
main()