summary refs log tree commit diff
path: root/pkgs/misc
diff options
context:
space:
mode:
authorMatthieu Coudron <mattator@gmail.com>2019-11-19 01:54:29 +0900
committerMatthieu Coudron <mattator@gmail.com>2019-11-19 18:41:11 +0900
commit3820ff9c8be01aecb5976996ae7d4eb3ef4c4b5c (patch)
treecceeef9aca81b5d37d9a8a4b221af1d88c70d553 /pkgs/misc
parent01037b305caf5b54f27550d81b13f77bf0d49033 (diff)
downloadnixpkgs-3820ff9c8be01aecb5976996ae7d4eb3ef4c4b5c.tar
nixpkgs-3820ff9c8be01aecb5976996ae7d4eb3ef4c4b5c.tar.gz
nixpkgs-3820ff9c8be01aecb5976996ae7d4eb3ef4c4b5c.tar.bz2
nixpkgs-3820ff9c8be01aecb5976996ae7d4eb3ef4c4b5c.tar.lz
nixpkgs-3820ff9c8be01aecb5976996ae7d4eb3ef4c4b5c.tar.xz
nixpkgs-3820ff9c8be01aecb5976996ae7d4eb3ef4c4b5c.tar.zst
nixpkgs-3820ff9c8be01aecb5976996ae7d4eb3ef4c4b5c.zip
vim update.py: allow different in and out files
...also adds an argparse cli parser.
Diffstat (limited to 'pkgs/misc')
-rwxr-xr-xpkgs/misc/vim-plugins/update.py53
1 files changed, 42 insertions, 11 deletions
diff --git a/pkgs/misc/vim-plugins/update.py b/pkgs/misc/vim-plugins/update.py
index 78abdbd6ab2..92a47bc5d13 100755
--- a/pkgs/misc/vim-plugins/update.py
+++ b/pkgs/misc/vim-plugins/update.py
@@ -8,6 +8,7 @@
 # linted:
 # $ nix run nixpkgs.python3Packages.flake8 -c flake8 --ignore E501,E265 update.py
 
+import argparse
 import functools
 import json
 import os
@@ -29,6 +30,8 @@ ATOM_LINK = "{http://www.w3.org/2005/Atom}link"
 ATOM_UPDATED = "{http://www.w3.org/2005/Atom}updated"
 
 ROOT = Path(__file__).parent
+DEFAULT_IN = ROOT.joinpath("vim-plugin-names")
+DEFAULT_OUT = ROOT.joinpath("generated.nix")
 
 
 class Repo:
@@ -209,9 +212,9 @@ def check_results(
 
 def parse_plugin_line(line: str) -> Tuple[str, str, str]:
     try:
-        name, repo = line.split('/')
+        name, repo = line.split("/")
         try:
-            repo, alias = repo.split(' as ')
+            repo, alias = repo.split(" as ")
             return (name, repo, alias.strip())
         except ValueError:
             # no alias defined
@@ -220,8 +223,7 @@ def parse_plugin_line(line: str) -> Tuple[str, str, str]:
         return (None, None, None)
 
 
-def load_plugin_spec() -> List[Tuple[str, str]]:
-    plugin_file = ROOT.joinpath("vim-plugin-names")
+def load_plugin_spec(plugin_file: str) -> List[Tuple[str, str]]:
     plugins = []
     with open(plugin_file) as f:
         for line in f:
@@ -305,10 +307,10 @@ header = (
 )
 
 
-def generate_nix(plugins: List[Tuple[str, str, Plugin]]):
+def generate_nix(plugins: List[Tuple[str, str, Plugin]], outfile: str):
     sorted_plugins = sorted(plugins, key=lambda v: v[2].name.lower())
 
-    with open(ROOT.joinpath("generated.nix"), "w+") as f:
+    with open(outfile, "w+") as f:
         f.write(header)
         f.write(
             """
@@ -338,15 +340,44 @@ let
   }};
 """
             )
-        f.write("""
+        f.write(
+            """
 });
 in lib.fix' (lib.extends overrides packages)
-""")
-    print("updated generated.nix")
+"""
+        )
+    print(f"updated {outfile}")
+
+
+def parse_args():
+    parser = argparse.ArgumentParser(
+        description=(
+            "Updates nix derivations for vim plugins"
+            f"By default from {DEFAULT_IN} to {DEFAULT_OUT}"
+        )
+    )
+    parser.add_argument(
+        "--input-names",
+        "-i",
+        dest="input_file",
+        default=DEFAULT_IN,
+        help="A list of plugins in the form owner/repo",
+    )
+    parser.add_argument(
+        "--out",
+        "-o",
+        dest="outfile",
+        default=DEFAULT_OUT,
+        help="Filename to save generated nix code",
+    )
+
+    return parser.parse_args()
 
 
 def main() -> None:
-    plugin_names = load_plugin_spec()
+
+    args = parse_args()
+    plugin_names = load_plugin_spec(args.input_file)
     current_plugins = get_current_plugins()
     cache = Cache(current_plugins)
 
@@ -362,7 +393,7 @@ def main() -> None:
 
     plugins = check_results(results)
 
-    generate_nix(plugins)
+    generate_nix(plugins, args.outfile)
 
 
 if __name__ == "__main__":