flake-modules/new-plugin: optionalize package name

New default behavior accepts just the upstream plugin name and performs
the same package name normalization from nixpkgs.
This commit is contained in:
Austin Horstman 2025-05-07 22:57:14 -05:00
parent c3b04f76ec
commit 94298096e8

View file

@ -39,6 +39,19 @@ test_nix_template = """{{
""" """
def normalized_name(name) -> str:
"""
Convert name to a normalized package name format.
Args:
name (str): The original name to normalize.
Returns:
str: The normalized package name.
"""
return name.replace(".", "-")
def kebab_case(input_string): def kebab_case(input_string):
""" """
Convert a string to kebab-case. Convert a string to kebab-case.
@ -122,12 +135,20 @@ def main():
parser.add_argument( parser.add_argument(
"originalName", type=str, help="Original name of the new plugin" "originalName", type=str, help="Original name of the new plugin"
) )
parser.add_argument("package", type=str, help="Package name of the new plugin") parser.add_argument(
"--package",
"-p",
type=str,
help="Package name of the new plugin (defaults to normalized version of originalName)",
)
args = parser.parse_args() args = parser.parse_args()
# Calculate name # Calculate name
name = kebab_case(args.originalName) name = kebab_case(args.originalName)
# Use provided package name or default to normalized original name
package = args.package if args.package else normalized_name(args.originalName)
# Define paths # Define paths
root_identifier = "flake.nix" root_identifier = "flake.nix"
root_dir = find_project_root(root_identifier) root_dir = find_project_root(root_identifier)
@ -141,7 +162,7 @@ def main():
default_nix_template, default_nix_template,
name, name,
args.originalName, args.originalName,
args.package, package,
) )
create_test_file( create_test_file(
test_path, test_path,