diff --git a/bin/vstarstack b/bin/vstarstack
index 875251c3..ed595c33 100755
--- a/bin/vstarstack
+++ b/bin/vstarstack
@@ -4,8 +4,21 @@ import sys
import vstarstack.tool.process
import vstarstack.tool.cfg
+import vstarstack.tool.usage
program_project = vstarstack.tool.cfg.get_project()
-program_argv = [item for item in sys.argv[1:] if item[:2] != "--"]
-vstarstack.tool.process.run(program_project, program_argv, 'vstarstack')
+if vstarstack.tool.cfg.get_param("autocomplete", bool, False):
+ #with open("complete", "w") as f:
+ # print(sys.argv, file=f)
+ program_argv = [item for item in sys.argv[2:] if item[:2] != "--"]
+ variants = vstarstack.tool.usage.autocompletion(vstarstack.tool.process.commands,
+ program_argv)
+ for variant in variants:
+ print(variant)
+else:
+ program_argv = [item for item in sys.argv[1:] if item[:2] != "--"]
+ vstarstack.tool.usage.run(program_project,
+ program_argv,
+ "",
+ vstarstack.tool.process.commands)
diff --git a/setup.py b/setup.py
index 0d1989c8..541a3f32 100644
--- a/setup.py
+++ b/setup.py
@@ -12,9 +12,8 @@
# along with this program. If not, see .
#
-from setuptools import setup, Extension, find_packages
-
import os
+from setuptools import setup, Extension
perspective = Extension(name="vstarstack.library.projection.perspective",
sources=["src/vstarstack/library/projection/perspective.c"])
@@ -29,7 +28,8 @@
sources=["src/vstarstack/library/fine_shift/image_wave.c"])
root = os.path.join(os.path.abspath(os.path.dirname(__file__)), "src")
-result = [os.path.join(dp, f) for dp, dn, filenames in os.walk(root) for f in filenames if os.path.splitext(f)[1] == '.py']
+result = [os.path.join(dp, f) for dp, dn, filenames in os.walk(root)
+ for f in filenames if os.path.splitext(f)[1] == '.py']
result = list(set([os.path.dirname(item[len(root)+1:]) for item in result]))
result = [item.replace("/",".") for item in result if "tests" not in item]
diff --git a/src/vstarstack/tool/calibration.py b/src/vstarstack/tool/calibration.py
index 30c59e22..17691fbb 100644
--- a/src/vstarstack/tool/calibration.py
+++ b/src/vstarstack/tool/calibration.py
@@ -125,6 +125,3 @@ def _process_build_flat_sky(_project : vstarstack.tool.cfg.Project,
"Create flat image - use sky images",
"flats/ flat.zip")
}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- vstarstack.tool.usage.run(project, argv, "calibration", commands, autohelp=True)
diff --git a/src/vstarstack/tool/cfg.py b/src/vstarstack/tool/cfg.py
index a29ec1df..f8c64d2b 100644
--- a/src/vstarstack/tool/cfg.py
+++ b/src/vstarstack/tool/cfg.py
@@ -23,7 +23,7 @@
def get_param(name, type_of_var, default):
"""Get cmdline parameter --name=value"""
- for arg in sys.argv[2:]:
+ for arg in sys.argv[1:]:
if arg[:2] != "--":
continue
arg = arg[2:]
diff --git a/src/vstarstack/tool/cluster.py b/src/vstarstack/tool/cluster.py
index c46891fb..1d4c7c38 100644
--- a/src/vstarstack/tool/cluster.py
+++ b/src/vstarstack/tool/cluster.py
@@ -105,6 +105,3 @@ def find_shift(project: vstarstack.tool.cfg.Project, argv: list):
"Find shifts from cluster file",
"cluster.json shifts.json"),
}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- vstarstack.tool.usage.run(project, argv, "cluster", commands, autohelp=True)
diff --git a/src/vstarstack/tool/fine_shift.py b/src/vstarstack/tool/fine_shift.py
index 479867ff..953e8794 100644
--- a/src/vstarstack/tool/fine_shift.py
+++ b/src/vstarstack/tool/fine_shift.py
@@ -141,7 +141,3 @@ def apply_alignment(project: vstarstack.tool.cfg.Project, argv: list):
"align-features": (find_alignment, "find alignment of images", "clusters.json alignments/"),
"apply-aligns": (apply_alignment, "apply alignments to images", "npys/ alignments/ output/"),
}
-
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- vstarstack.tool.usage.run(project, argv, "fine-shift", commands, autohelp=True)
diff --git a/src/vstarstack/tool/image.py b/src/vstarstack/tool/image.py
index 82d8ed49..e2eee31a 100644
--- a/src/vstarstack/tool/image.py
+++ b/src/vstarstack/tool/image.py
@@ -182,7 +182,3 @@ def _exposures(_project, argv):
"rename-channel": (_rename_channel, "filename.zip original_name target_name - rename channel"),
"exposure": (_exposures, "display image exposures per channel", "file.zip"),
}
-
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- vstarstack.tool.usage.run(project, argv, "image", commands, autohelp=True)
diff --git a/src/vstarstack/tool/image_processing/blur.py b/src/vstarstack/tool/image_processing/blur.py
index 6fec2140..8d763cc1 100644
--- a/src/vstarstack/tool/image_processing/blur.py
+++ b/src/vstarstack/tool/image_processing/blur.py
@@ -44,7 +44,7 @@ def process_dir(argv):
with mp.Pool(vstarstack.tool.cfg.nthreads) as pool:
pool.starmap(blur, args)
-def process(project: vstarstack.tool.cfg.Project, argv: list):
+def run(project: vstarstack.tool.cfg.Project, argv: list):
if len(argv) > 0:
if os.path.isdir(argv[0]):
process_dir(argv)
@@ -53,7 +53,3 @@ def process(project: vstarstack.tool.cfg.Project, argv: list):
else:
process_dir([project.config.paths.npy_fixed,
project.config.paths.npy_fixed])
-
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- process(project, argv)
diff --git a/src/vstarstack/tool/image_processing/border.py b/src/vstarstack/tool/image_processing/border.py
index 1ca839ff..923fa229 100644
--- a/src/vstarstack/tool/image_processing/border.py
+++ b/src/vstarstack/tool/image_processing/border.py
@@ -71,7 +71,7 @@ def process_dir(argv):
brd_left, brd_top, brd_right, brd_bottom) for name, fname in files])
-def process(project: vstarstack.tool.cfg.Project, argv: list):
+def run(project: vstarstack.tool.cfg.Project, argv: list):
if len(argv) > 0:
if os.path.isdir(argv[0]):
process_dir(argv)
@@ -80,12 +80,3 @@ def process(project: vstarstack.tool.cfg.Project, argv: list):
else:
process_dir([project.config.paths.npy_fixed,
project.config.paths.npy_fixed])
-
-
-commands = {
- "*": (process, "remove border", "(input.zip output.zip | [input/ output/])"),
-}
-
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- vstarstack.tool.usage.run(project, argv, "image-process border", commands)
diff --git a/src/vstarstack/tool/image_processing/distorsion.py b/src/vstarstack/tool/image_processing/distorsion.py
index 283ed527..4d20996a 100644
--- a/src/vstarstack/tool/image_processing/distorsion.py
+++ b/src/vstarstack/tool/image_processing/distorsion.py
@@ -48,7 +48,7 @@ def _process_dir(distorsion : vstarstack.library.image_process.distorsion.Distor
pool.starmap(dedistorsion, [(distorsion, name, fname, os.path.join(
outpath, name + ".zip")) for name, fname in files])
-def _process(project: vstarstack.tool.cfg.Project, argv: list):
+def run(project: vstarstack.tool.cfg.Project, argv: list):
a = project.distorsion["a"]
b = project.distorsion["b"]
c = project.distorsion["c"]
@@ -62,10 +62,3 @@ def _process(project: vstarstack.tool.cfg.Project, argv: list):
else:
_process_dir(distorsion, [project.config.paths.npy_fixed,
project.config.paths.npy_fixed])
-
-commands = {
- "*": (_process, "Remove distrosion", "(input.file output.file | [input/ output/])"),
-}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- vstarstack.tool.usage.run(project, argv, "image-process distorsion", commands)
diff --git a/src/vstarstack/tool/image_processing/fixes.py b/src/vstarstack/tool/image_processing/fixes.py
index a996cd75..39910fed 100644
--- a/src/vstarstack/tool/image_processing/fixes.py
+++ b/src/vstarstack/tool/image_processing/fixes.py
@@ -43,12 +43,8 @@ def copy(project: vstarstack.tool.cfg.Project, argv: list):
commands = {
"copy": (copy, "just copy images from original to pipeline dir"),
"distorsion": (vstarstack.tool.image_processing.distorsion.run, "fix distorsion"),
- "remove-sky": (vstarstack.tool.image_processing.remove_sky.run, "remove sky"),
+ "remove-sky": (vstarstack.tool.image_processing.remove_sky.commands, "remove sky"),
"border": (vstarstack.tool.image_processing.border.run, "remove border"),
"normalize": (vstarstack.tool.image_processing.normalize.run, "normalize to weight"),
"blur": (vstarstack.tool.image_processing.blur.run, "gaussian blur"),
}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- """Run image fix methods"""
- vstarstack.tool.usage.run(project, argv, "image-process", commands, autohelp=True)
diff --git a/src/vstarstack/tool/image_processing/remove_sky.py b/src/vstarstack/tool/image_processing/remove_sky.py
index 63d237da..9b4bf44e 100644
--- a/src/vstarstack/tool/image_processing/remove_sky.py
+++ b/src/vstarstack/tool/image_processing/remove_sky.py
@@ -69,8 +69,3 @@ def process(project: vstarstack.tool.cfg.Project, argv: list, model_name : str):
"quadratic": (lambda project, argv: process(project, argv, "quadratic"),
"use quadratic gradient model"),
}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- """Run removing of sky"""
- vstarstack.tool.usage.run(
- project, argv, "image-process remove-sky", commands, autohelp=True)
diff --git a/src/vstarstack/tool/merge.py b/src/vstarstack/tool/merge.py
index e01de620..510d4c80 100644
--- a/src/vstarstack/tool/merge.py
+++ b/src/vstarstack/tool/merge.py
@@ -60,6 +60,3 @@ def sigma_clip(project: vstarstack.tool.cfg.Project, argv: list):
"simple": (simple_add, "simple add images"),
"sigma-clip": (sigma_clip, "add images with sigma clipping"),
}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- vstarstack.tool.usage.run(project, argv, "merge", commands, autohelp=True)
diff --git a/src/vstarstack/tool/objects/detect.py b/src/vstarstack/tool/objects/detect.py
index e1e44738..158ca5d6 100644
--- a/src/vstarstack/tool/objects/detect.py
+++ b/src/vstarstack/tool/objects/detect.py
@@ -105,10 +105,3 @@ def _process_disc(project, argv):
"detect compact objects with disc detector",
"npy/ descs/"),
}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- vstarstack.tool.usage.run(project,
- argv,
- "objects detect",
- commands,
- autohelp=True)
diff --git a/src/vstarstack/tool/objects/objects.py b/src/vstarstack/tool/objects/objects.py
index 4ad3973d..dee5f3f3 100644
--- a/src/vstarstack/tool/objects/objects.py
+++ b/src/vstarstack/tool/objects/objects.py
@@ -25,9 +25,6 @@ def _enable_objects(project : vstarstack.tool.cfg.Project, _argv: list[str]):
commands = {
"config": (_enable_objects, "configure compact_objects pipeline"),
- "detect": (vstarstack.tool.objects.detect.run, "detect compact objects"),
+ "detect": (vstarstack.tool.objects.detect.commands, "detect compact objects"),
"cut": (vstarstack.tool.objects.cut.run, "cut compact objects"),
}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list[str]):
- vstarstack.tool.usage.run(project, argv, "objects", commands, autohelp=True)
diff --git a/src/vstarstack/tool/planets/buildmap.py b/src/vstarstack/tool/planets/buildmap.py
index b3188e93..8d9399c6 100644
--- a/src/vstarstack/tool/planets/buildmap.py
+++ b/src/vstarstack/tool/planets/buildmap.py
@@ -34,8 +34,8 @@ def _process_path(project : vstarstack.tool.cfg.Project,
out = os.path.join(maps_path, name + ".zip")
_process_file(project, filename, out)
-def _process(project : vstarstack.tool.cfg.Project,
- argv : list[str]):
+def run(project : vstarstack.tool.cfg.Project,
+ argv : list[str]):
if len(argv) > 0:
input_path = argv[0]
output_path = argv[1]
@@ -47,10 +47,3 @@ def _process(project : vstarstack.tool.cfg.Project,
_process_path(project,
project.config.paths.aligned,
project.config.planets.paths.maps)
-
-commands = {
- "*": (_process, "build surface map from image", "aligned/ maps/"),
-}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list[str]):
- vstarstack.tool.usage.run(project, argv, "planets buildmap", commands)
diff --git a/src/vstarstack/tool/planets/planets.py b/src/vstarstack/tool/planets/planets.py
index 340239bd..32213d4e 100644
--- a/src/vstarstack/tool/planets/planets.py
+++ b/src/vstarstack/tool/planets/planets.py
@@ -25,6 +25,3 @@ def _enable_planets(project : vstarstack.tool.cfg.Project, _argv: list[str]):
"configure": (_enable_planets, "configure planets in project"),
"buildmap": (vstarstack.tool.planets.buildmap.run, "build planet surface map"),
}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- vstarstack.tool.usage.run(project, argv, "planets", commands, autohelp=True)
diff --git a/src/vstarstack/tool/process.py b/src/vstarstack/tool/process.py
index d3f74db0..598d688d 100644
--- a/src/vstarstack/tool/process.py
+++ b/src/vstarstack/tool/process.py
@@ -13,8 +13,6 @@
#
-import sys
-
import vstarstack.tool.cfg
import vstarstack.tool.usage
import vstarstack.tool.manage_project
@@ -34,45 +32,33 @@
import vstarstack.tool.calibration
commands = {
- "readimage": (vstarstack.tool.readimage.run,
+ "readimage": (vstarstack.tool.readimage.commands,
"read source images to npz"),
"debayer": (vstarstack.tool.debayer.run,
"debayer RAW images"),
- "image-process": (vstarstack.tool.image_processing.fixes.run,
+ "image-process": (vstarstack.tool.image_processing.fixes.commands,
"image-process - make optical fixes and other image fixes"),
- "calibration": (vstarstack.tool.calibration.run,
+ "calibration": (vstarstack.tool.calibration.commands,
"calibration - flats, darks"),
- "objects": (vstarstack.tool.objects.objects.run,
- "commands for processing images with compact objects (planets, diffractions, etc)"),
- "stars": (vstarstack.tool.stars.stars.run,
+ "objects": (vstarstack.tool.objects.objects.commands,
+ "commands for processing images with compact objects " +
+ "(planets, diffractions, etc)"),
+ "stars": (vstarstack.tool.stars.stars.commands,
"commands for processing stars images"),
- "cluster": (vstarstack.tool.cluster.run,
+ "cluster": (vstarstack.tool.cluster.commands,
"command for cluster processing"),
- "shift": (vstarstack.tool.shift.run,
+ "shift": (vstarstack.tool.shift.commands,
"move and rotate images to match them"),
- "merge": (vstarstack.tool.merge.run,
+ "merge": (vstarstack.tool.merge.commands,
"merge images", "input_dir/ output.npz"),
"project": (vstarstack.tool.manage_project.run,
"configurate project"),
# "planets": (vstarstack.targets.planets.planets.run,
# "commands for processing planets"),
- "image": (vstarstack.tool.image.run,
+ "image": (vstarstack.tool.image.commands,
"image processing (show, convert, etc)"),
"clean": (vstarstack.tool.clean.run,
"remove temporary files"),
- "fine-shift": (vstarstack.tool.fine_shift.run,
+ "fine-shift": (vstarstack.tool.fine_shift.commands,
"fine shift images"),
}
-
-
-def run(project: vstarstack.tool.cfg.Project, argv: list, progname=None):
- """Run program"""
- if progname is not None:
- vstarstack.tool.usage.setprogname(progname)
- vstarstack.tool.usage.run(project, argv, "", commands, autohelp=True)
-
-
-if __name__ == "__main__":
- program_project = vstarstack.tool.cfg.get_project()
- program_argv = [item for item in sys.argv[2:] if item[:2] != "--"]
- run(program_project, program_argv, sys.argv[1])
diff --git a/src/vstarstack/tool/readimage.py b/src/vstarstack/tool/readimage.py
index 97afb559..b1625f5a 100644
--- a/src/vstarstack/tool/readimage.py
+++ b/src/vstarstack/tool/readimage.py
@@ -110,7 +110,3 @@ def _read_video(project: vstarstack.tool.cfg.Project, argv: list):
"fits": (_read_fits, "read FITS images"),
"video": (_read_video, "read VIDEO images"),
}
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- """Run reading image files"""
- vstarstack.tool.usage.run(project, argv, "readimage", commands, autohelp=True)
diff --git a/src/vstarstack/tool/stars/stars.py b/src/vstarstack/tool/stars/stars.py
index 1eb5fc68..138649f0 100644
--- a/src/vstarstack/tool/stars/stars.py
+++ b/src/vstarstack/tool/stars/stars.py
@@ -31,9 +31,6 @@ def _enable_stars(project : vstarstack.tool.cfg.Project, _argv: list[str]):
"detect": (vstarstack.tool.stars.detect.run, "detect stars"),
"describe": (vstarstack.tool.stars.describe.run, "find descriptions for each image"),
"match": (vstarstack.tool.stars.match.run, "match stars between images"),
- "cluster": (vstarstack.tool.stars.build_clusters.run, "find matching stars clusters between images"),
+ "cluster": (vstarstack.tool.stars.build_clusters.run,
+ "find matching stars clusters between images"),
}
-
-
-def run(project: vstarstack.tool.cfg.Project, argv: list):
- vstarstack.tool.usage.run(project, argv, "stars", commands, autohelp=True)
diff --git a/src/vstarstack/tool/usage.py b/src/vstarstack/tool/usage.py
index f692b5d0..723a6450 100644
--- a/src/vstarstack/tool/usage.py
+++ b/src/vstarstack/tool/usage.py
@@ -12,6 +12,8 @@
# along with this program. If not, see .
#
+import sys
+import vstarstack.tool.cfg
_PRGNAME = "vstarstack"
def setprogname(name : str):
@@ -19,6 +21,25 @@ def setprogname(name : str):
global _PRGNAME
_PRGNAME = name
+def autocompletion(commands : dict, argv : list):
+ """Autocompletion"""
+ if len(argv) == 0:
+ current_input = ""
+ else:
+ current_input = argv[0]
+ for cmd in commands:
+ if cmd == current_input:
+ submodule = commands[cmd][0]
+ if isinstance(submodule, dict):
+ return autocompletion(submodule, argv[1:])
+ return []
+
+ variants = []
+ for cmd in commands:
+ if cmd.startswith(current_input):
+ variants.append(cmd)
+ return variants
+
def usage(base : str, commands : dict, message : str):
"""Display usage"""
print(f"Usage: {_PRGNAME} {base} command ...")
@@ -34,31 +55,36 @@ def usage(base : str, commands : dict, message : str):
extra = commands[cmd][2]
print(f"{cmd} - {desc}\n\t{_PRGNAME} {base} {cmd} {extra}\n")
else:
- print(f"{cmd} - {desc}\n\t{_PRGNAME} {base} {cmd}...\n")
+ print(f"{cmd} - {desc}\n\t{_PRGNAME} {base} {cmd} ...\n")
else:
if len(commands[cmd]) >= 3:
extra = commands[cmd][2]
print(f"(default) - {desc}\n\t{_PRGNAME} {base} {extra}\n")
else:
- print(f"(default) - {desc}\n\t{_PRGNAME} {base}...\n")
+ print(f"(default) - {desc}\n\t{_PRGNAME} {base} ...\n")
print("help - print usage")
print(f"\t{_PRGNAME} {base} [help]\n")
-def run(project, argv, base, commands, message=None, autohelp=False):
+def run(project, argv, base, commands, message=None):
"""Run usage"""
- if (autohelp and len(argv) == 0) or (len(argv) > 0 and argv[0] == "help"):
+ if (len(argv) == 0) or (len(argv) > 0 and argv[0] == "help"):
usage(base, commands, message)
return
- if len(argv) > 0:
- cmd = argv[0]
+ cmd = argv[0]
+ if cmd not in commands:
+ print(f"Command {cmd} not found!")
+ usage(base, commands, message)
+ return
- if cmd not in commands:
- print(f"Command {cmd} not found!")
- usage(base, commands, message)
- return
- commands[cmd][0](project, argv[1:])
+ submodule = commands[cmd][0]
+ if isinstance(submodule, dict):
+ if len(base) > 0:
+ new_base = base + " " + cmd
+ else:
+ new_base = cmd
+ run(project, argv[1:], new_base, submodule, message)
else:
- commands["*"][0](project, argv)
+ submodule(project, argv[1:])
diff --git a/vstarstack_completion b/vstarstack_completion
new file mode 100644
index 00000000..a53b5c48
--- /dev/null
+++ b/vstarstack_completion
@@ -0,0 +1,6 @@
+_vstarstack()
+{
+ res=$(vstarstack ${COMP_LINE} --autocomplete=True)
+ COMPREPLY=($res)
+}
+complete -F _vstarstack vstarstack