Skip to content

Commit

Permalink
refactor: rename completion generator option
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoshiu committed Apr 27, 2024
1 parent 112cc06 commit b5c4b14
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 31 additions & 21 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 48 additions & 41 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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;
}
));
}
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ struct Cli {
#[arg(short, long, action = ArgAction::Count)]
verbose: u8,

#[arg(long = "generate", action = ArgAction::Set)]
generator: Option<Shell>,
#[arg(long, value_name = "SHELL")]
completion: Option<Shell>,
}

#[tokio::main]
Expand All @@ -39,7 +39,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
_ => (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());
Expand Down

0 comments on commit b5c4b14

Please sign in to comment.