From b5c4b1499c095dd6e73848a615044f570da22dab Mon Sep 17 00:00:00 2001 From: yaoshiu Date: Sat, 27 Apr 2024 22:34:55 +0800 Subject: [PATCH] refactor: rename completion generator option --- Cargo.lock | 2 +- Cargo.toml | 2 +- flake.lock | 52 ++++++++++++++++++------------- flake.nix | 89 +++++++++++++++++++++++++++++------------------------ src/main.rs | 6 ++-- 5 files changed, 84 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae230e9..3880066 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -921,7 +921,7 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "pretty-derby" -version = "0.4.0" +version = "0.4.1" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index cce04a4..ff5f300 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "pretty-derby" authors = ["Phie Ash"] description = "Hachimi hachimi hachimi~" -version = "0.4.1" +version = "0.4.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/flake.lock b/flake.lock index c1ed282..b06f282 100644 --- a/flake.lock +++ b/flake.lock @@ -2,23 +2,20 @@ "nodes": { "fenix": { "inputs": { - "nixpkgs": [ - "nixpkgs" - ], + "nixpkgs": "nixpkgs", "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1709878902, - "narHash": "sha256-4cVeNZMZWUIf9XS285BD4VPPco1CosBLq4pc0aL5IUA=", + "lastModified": 1714199028, + "narHash": "sha256-QO3Yv3UfJRfhZE1wsHOartg+k8/Kf1BiDyfl8eEpqcE=", "owner": "nix-community", "repo": "fenix", - "rev": "3c913ad893d6304a637b5383057bdab5543e9e92", + "rev": "055f6db376eaf544d84aa55bd5a7c70634af41ba", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" + "id": "fenix", + "type": "indirect" } }, "flake-utils": { @@ -26,17 +23,16 @@ "systems": "systems" }, "locked": { - "lastModified": 1709126324, - "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "d465f4819400de7c8d874d50b982301f28a84605", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" + "id": "flake-utils", + "type": "indirect" } }, "naersk": { @@ -61,26 +57,40 @@ }, "nixpkgs": { "locked": { - "lastModified": 1709703039, - "narHash": "sha256-6hqgQ8OK6gsMu1VtcGKBxKQInRLHtzulDo9Z5jxHEFY=", - "owner": "NixOS", + "lastModified": 1714076141, + "narHash": "sha256-Drmja/f5MRHZCskS6mvzFqxEaZMeciScCTFxWVLqWEY=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "9df3e30ce24fd28c7b3e2de0d986769db5d6225d", + "rev": "7bb2ccd8cdc44c91edba16c48d2c8f331fb3d856", "type": "github" }, "original": { - "owner": "NixOS", + "owner": "nixos", "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1714091391, + "narHash": "sha256-68n3GBvlm1MIeJXadPzQ3v8Y9sIW3zmv8gI5w5sliC8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4c86138ce486d601d956a165e2f7a0fc029a03c1", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, "root": { "inputs": { "fenix": "fenix", "flake-utils": "flake-utils", "naersk": "naersk", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs_2" } }, "rust-analyzer-src": { diff --git a/flake.nix b/flake.nix index 3ca9a5b..ddcf910 100644 --- a/flake.nix +++ b/flake.nix @@ -1,58 +1,56 @@ { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - fenix = { - url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - flake-utils.url = "github:numtide/flake-utils"; naersk = { url = "github:nix-community/naersk"; inputs.nixpkgs.follows = "nixpkgs"; }; }; - outputs = { fenix, flake-utils, naersk, nixpkgs, self }: + outputs = { - overlays = rec { - dev = final: prev: - let - system = final.hostPlatform.system; - toolchain = with fenix.packages.${system}; combine [ + fenix, + flake-utils, + naersk, + nixpkgs, + self, + }: + { + overlays.default = + final: prev: + let + inherit (final.hostPlatform) system; + toolchain = + with fenix.packages.${system}; + combine [ minimal.cargo minimal.rustc ]; - naersk-lib = naersk.lib.${system}.override { - cargo = toolchain; - rustc = toolchain; - }; - in - { - pretty-derby = naersk-lib.buildPackage { - nativeBuildInputs = with final; lib.optional stdenv.isDarwin [ - darwin.apple_sdk.frameworks.SystemConfiguration - ]; - src = ./.; - }; - - pretty-derby-shell = with final; mkShell { - buildInputs = [ - toolchain - iconv - ] ++ (lib.optional stdenv.isDarwin [ - darwin.apple_sdk.frameworks.SystemConfiguration - ]); - }; + naersk-lib = naersk.lib.${system}.override { + cargo = toolchain; + rustc = toolchain; }; - - default = final: prev: { inherit (dev) pretty-derby; }; - }; - } // - (flake-utils.lib.eachDefaultSystem (system: + in + { + pretty-derby = naersk-lib.buildPackage { + nativeBuildInputs = + with final; + (lib.optional stdenv.isDarwin [ darwin.apple_sdk.frameworks.SystemConfiguration ]) + ++ [ installShellFiles ]; + src = ./.; + postFixup = '' + for shell in bash fish zsh; do + installShellCompletion --cmd pretty-derby --$shell <($out/bin/pretty-derby --completion $shell) + done + ''; + }; + }; + } + // (flake-utils.lib.eachDefaultSystem ( + system: let pkgs = (import nixpkgs) { inherit system; - overlays = [ self.overlays.dev ]; + overlays = [ self.overlays.default ]; }; in { @@ -61,7 +59,16 @@ default = pretty-derby; }; + devShells.default = + with pkgs; + mkShell { + buildInputs = [ + toolchain + iconv + ] ++ (lib.optional stdenv.isDarwin [ darwin.apple_sdk.frameworks.SystemConfiguration ]); + }; - devShells.default = pkgs.pretty-derby-shell; - })); + formatter = pkgs.nixfmt-rfc-style; + } + )); } diff --git a/src/main.rs b/src/main.rs index 212e81b..9427f7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,8 +25,8 @@ struct Cli { #[arg(short, long, action = ArgAction::Count)] verbose: u8, - #[arg(long = "generate", action = ArgAction::Set)] - generator: Option, + #[arg(long, value_name = "SHELL")] + completion: Option, } #[tokio::main] @@ -39,7 +39,7 @@ async fn main() -> Result<(), Box> { _ => (Level::Trace, LevelFilter::Trace), }; - if let Some(generator) = cli.generator { + if let Some(generator) = cli.completion { let mut cmd = Cli::command(); let name = cmd.get_name().to_string(); generate(generator, &mut cmd, name, &mut io::stdout());