~rootmos/fetch

439a01fc257bb5ffdcebf50d1fa95344bd7b4590 — Gustav Behm 4 months ago 8c8cb61
Add help-text for the --root and --manifest arguments
2 files changed, 17 insertions(+), 14 deletions(-)

M README.md
M fetch
M README.md => README.md +8 -8
@@ 3,21 3,21 @@ File download helpers

## Usage
```
usage: fetch [-h] [--log LOG] [--log-file FILE] [--manifest MANIFEST]
             [--root ROOT]
usage: fetch [-h] [--log LOG] [--log-file FILE] [--root ROOT]
             [--manifest FILE]
             {add,download} ...

One script to fetch them all and in /tmp bind them.
One script to fetch them all and in /tmp bind them

positional arguments:
  {add,download}

options:
  -h, --help           show this help message and exit
  --log LOG            set log level (default: WARN)
  --log-file FILE      redirect stdout and stderr to FILE (default: None)
  --manifest MANIFEST
  --root ROOT
  -h, --help       show this help message and exit
  --log LOG        set log level (default: WARN)
  --log-file FILE  redirect stdout and stderr to FILE (default: None)
  --root ROOT      act relative the directory ROOT (default: .)
  --manifest FILE  load manifest from DIR (default: ./.fetch.json)
```

### Add a file

M fetch => fetch +9 -6
@@ 18,19 18,20 @@ def env(var, default=None):

def parse_args():
    parser = argparse.ArgumentParser(
            description="One script to fetch them all and in /tmp bind them.",
            description="One script to fetch them all and in /tmp bind them",
            formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("--log", default=env("LOG_LEVEL", "WARN"), help="set log level")
    parser.add_argument("--log-file", metavar="FILE", default=env("LOG_FILE"), help="redirect stdout and stderr to FILE")

    parser.add_argument("--manifest", metavar="MANIFEST", default=env("MANIFEST"))
    parser.add_argument("--root", metavar="ROOT", default=env("ROOT"))
    default_root = env("ROOT", ".")
    default_manifest = env("MANIFEST", os.path.join(default_root, ".fetch.json"))
    parser.add_argument("--root", metavar="ROOT", default=default_root, help="act relative the directory ROOT")
    parser.add_argument("--manifest", metavar="FILE", default=default_manifest, help="load manifest from DIR")

    subparsers = parser.add_subparsers(dest="cmd")

    add_cmd = subparsers.add_parser("add")

    add_cmd.add_argument("--sha256", metavar="SHA256")
    add_cmd.add_argument("url", metavar="URL")
    add_cmd.add_argument("target", metavar="TARGET")


@@ 189,8 190,10 @@ if __name__ == "__main__":
    logger = setup_logger(args.log.upper())
    logger.debug(f"args: {args}")

    root = args.root or os.getcwd()
    manifest = Manifest(args.manifest or os.path.join(root, ".fetch.json"))
    root = args.root
    if root == ".":
        root = os.getcwd()
    manifest = Manifest(args.manifest)

    if args.cmd == "add":
        target = os.path.relpath(os.path.join(root, args.target), start=root)