diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ef5701e..f0e21c9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,9 +33,9 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.pyv }} - - name: Test main.py + - name: Test src/main.py run: | - python ./main.py + python src/main.py - name: Test cli.py shell: bash run: | diff --git a/README.md b/README.md index beecb28..4fc9928 100644 --- a/README.md +++ b/README.md @@ -12,18 +12,20 @@ convert Ezon gpx files ## Usage -### Python +### Source -see [./main.py](./main.py#L141) +#### Python -### CLI +see [./src/main.py](./src/main.py#L141) + +#### CLI ```bash -./cli.py test/test.gpx [path] +./src/cli.py test/test.gpx [path] ``` ```bash -./cli.py --help +./src/cli.py --help ``` ## Develop Env diff --git a/cli.py b/cli.py deleted file mode 100644 index d543f48..0000000 --- a/cli.py +++ /dev/null @@ -1,45 +0,0 @@ -import argparse -from os import listdir -from os.path import join, isdir - -from main import convert - - -parser = argparse.ArgumentParser(prog="ezon-gpx") - -parser.add_argument( - "path", - nargs="+", -) -parser.add_argument("-o", "--out", help="the filename of output") -parser.add_argument( - "-d", "--dir", help="the dest dir of output", type=str, default="dist" -) -parser.add_argument("--hour", help="hour offset", type=int, default=-8) -parser.add_argument( - "--indent", help="output file with indent", type=bool, default=False -) -parser.add_argument("--strict", help="strict", type=bool, default=False) -args = parser.parse_args() - -print() -print("====== ezon-gpx cli ======") -print(args) - -paths = [] -for path in args.path: - if path.endswith(".gpx"): - paths.append(path) - elif isdir(path): - for p in listdir(path): - if p.endswith(".gpx"): - paths.append(join(path, p)) - - -for path in paths: - print() - print("[cli.py]", "processing", path) - convert(path, args.out, args.dir, args.hour, args.indent, args.strict) - -print() -print("[cli.py]", "processed files:", len(paths)) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b004e99 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "ezon-gpx" +version = "0.1.0" +authors = [ + {name = "Uiolee"}, +] +readme = "README.md" +license = {text = "MPL-2.0"} + +[project.scripts] +ezon-gpx = "cli:cli" + diff --git a/src/cli.py b/src/cli.py new file mode 100644 index 0000000..fa9a2a6 --- /dev/null +++ b/src/cli.py @@ -0,0 +1,45 @@ +import argparse +from os import listdir +from os.path import join, isdir + +from main import convert + + +def cli(): + parser = argparse.ArgumentParser(prog="ezon-gpx") + + parser.add_argument( + "path", + nargs="+", + ) + parser.add_argument("-o", "--out", help="the filename of output") + parser.add_argument( + "-d", "--dir", help="the dest dir of output", type=str, default="dist" + ) + parser.add_argument("--hour", help="hour offset", type=int, default=-8) + parser.add_argument( + "--indent", help="output file with indent", type=bool, default=False + ) + parser.add_argument("--strict", help="strict", type=bool, default=False) + args = parser.parse_args() + + print() + print("====== ezon-gpx cli ======") + print(args) + + paths = [] + for path in args.path: + if path.endswith(".gpx"): + paths.append(path) + elif isdir(path): + for p in listdir(path): + if p.endswith(".gpx"): + paths.append(join(path, p)) + + for path in paths: + print() + print("[cli.py]", "processing", path) + convert(path, args.out, args.dir, args.hour, args.indent, args.strict) + + print() + print("[cli.py]", "processed files:", len(paths)) diff --git a/main.py b/src/main.py similarity index 100% rename from main.py rename to src/main.py diff --git a/test/cli.test.sh b/test/cli.test.sh index 82218b6..926786a 100644 --- a/test/cli.test.sh +++ b/test/cli.test.sh @@ -1,3 +1,3 @@ #!/bin/bash -python cli.py test \ No newline at end of file +python src/cli.py test \ No newline at end of file