From aac7f3854e2a12720223c54bbf81218ac7375b54 Mon Sep 17 00:00:00 2001 From: Petr Portnov | PROgrm_JARvis Date: Sun, 02 Jun 2024 21:45:45 +0000 Subject: [PATCH] fix(fleet-cmd): include the required package for tab completions (#5) * fix(fleet-cmd): include the required package for tab completions * style(fleet-cmd): reformat automatically --- --- a/cmds/fleet/src/better_nix_eval.rs +++ b/cmds/fleet/src/better_nix_eval.rs @@ -1,25 +1,24 @@ //! Wrapper around nix repl, which allows to work on nix code, without relying on //! nix libexpr. I mean, nix libexpr is good, but until it has no C bindings, this is the royal PITA. -use std::collections::HashMap; -use std::ffi::{OsStr, OsString}; -use std::fmt::{self, Display}; -use std::path::PathBuf; -use std::process::Stdio; -use std::sync::{Arc, OnceLock}; +use std::{ + collections::HashMap, + ffi::{OsStr, OsString}, + fmt::{self, Display}, + path::PathBuf, + process::Stdio, + sync::{Arc, OnceLock}, +}; use anyhow::{anyhow, bail, ensure, Context, Result}; use better_command::{ClonableHandler, Handler, NixHandler, NoopHandler}; use futures::StreamExt; use itertools::Itertools; -use serde::de::DeserializeOwned; -use serde::{Deserialize, Serialize}; -use tokio::io::AsyncWriteExt; -use tokio::process::{ChildStderr, ChildStdin, ChildStdout, Command}; -use tokio::select; -use tokio::sync::{mpsc, oneshot, Mutex}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use tokio::{ + io::AsyncWriteExt, + process::{ChildStderr, ChildStdin, ChildStdout, Command}, + select, + sync::{mpsc, oneshot, Mutex}, +}; use tracing::{debug, error, warn, Level}; - - - - --- a/cmds/fleet/src/cmds/build_systems.rs +++ b/cmds/fleet/src/cmds/build_systems.rs @@ -1,9 +1,5 @@ -use std::os::unix::fs::symlink; -use std::path::PathBuf; -use std::{env::current_dir, time::Duration}; +use std::{env::current_dir, os::unix::fs::symlink, path::PathBuf, time::Duration}; -use crate::command::MyCommand; -use crate::host::{Config, ConfigHost}; use anyhow::{anyhow, Result}; use clap::{Parser, ValueEnum}; use itertools::Itertools as _; @@ -11,6 +7,11 @@ use tokio::{task::LocalSet, time::sleep}; use tracing::{error, field, info, info_span, warn, Instrument}; +use crate::{ + command::MyCommand, + host::{Config, ConfigHost}, +}; + #[derive(Parser)] pub struct Deploy { /// Disable automatic rollback --- a/cmds/fleet/src/cmds/info.rs +++ b/cmds/fleet/src/cmds/info.rs @@ -1,10 +1,11 @@ use std::collections::BTreeSet; -use crate::host::Config; use anyhow::{ensure, Result}; use clap::Parser; use nix_eval::nix_go_json; +use crate::host::Config; + #[derive(Parser)] pub struct Info { #[clap(long)] --- a/cmds/fleet/src/cmds/mod.rs +++ b/cmds/fleet/src/cmds/mod.rs @@ -1,4 +1,4 @@ pub mod build_systems; +pub mod complete; pub mod info; pub mod secrets; -pub mod complete; --- a/cmds/fleet/src/extra_args.rs +++ b/cmds/fleet/src/extra_args.rs @@ -1,7 +1,7 @@ -use anyhow::anyhow; -use anyhow::Result; use std::ffi::{OsStr, OsString}; +use anyhow::{anyhow, Result}; + pub fn parse_os(os: &OsStr) -> Result> { Ok(shlex::bytes::split(os.as_encoded_bytes()) .ok_or_else(|| anyhow!("invalid arguments"))? --- a/cmds/fleet/src/keys.rs +++ b/cmds/fleet/src/keys.rs @@ -1,12 +1,13 @@ use std::str::FromStr; -use crate::host::Config; use age::Recipient; use anyhow::{anyhow, Result}; use futures::{StreamExt, TryStreamExt}; use itertools::Itertools; use tracing::warn; +use crate::host::Config; + impl Config { pub fn cached_key(&self, host: &str) -> Option { let data = self.data(); --- a/cmds/fleet/src/main.rs +++ b/cmds/fleet/src/main.rs @@ -175,10 +175,20 @@ reg.init(); } -#[tokio::main] -async fn main() -> ExitCode { +fn main() -> ExitCode { + let opts = RootOpts::parse(); + if let Opts::Complete(c) = &opts.command { + c.run(RootOpts::command()); + return ExitCode::SUCCESS; + } + setup_logging(); - if let Err(e) = main_real().await { + async_main(opts) +} + +#[tokio::main] +async fn async_main(opts: RootOpts) -> ExitCode { + if let Err(e) = main_real(opts).await { // If I remove this line, the next error!() line gets eaten. // This is a bug in indicatif, it needs to be fixed #[cfg(feature = "indicatif")] @@ -189,14 +199,13 @@ ExitCode::SUCCESS } -async fn main_real() -> Result<()> { +async fn main_real(opts: RootOpts) -> Result<()> { nix_eval::init_tokio(); let nix_args = std::env::var_os("NIX_ARGS") .map(|a| extra_args::parse_os(&a)) .transpose()? .unwrap_or_default(); - let opts = RootOpts::parse(); let config = opts.fleet_opts.build(nix_args).await?; match run_command(&config, opts.command).await { --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1717025063, - "narHash": "sha256-dIubLa56W9sNNz0e8jGxrX3CAkPXsq7snuFA/Ie6dn8=", + "lastModified": 1717290123, + "narHash": "sha256-K8O2KQEbA+NIAc8BDsWV6QKqU3i9M+YTUi4zzmLRy1s=", "owner": "ipetkov", "repo": "crane", - "rev": "480dff0be03dac0e51a8dfc26e882b0d123a450e", + "rev": "ae1453ffd0f8f684e863685c317a953317db2b79", "type": "github" }, "original": { @@ -40,11 +40,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1717282945, - "narHash": "sha256-Jrn+/CdB/d2hUqduYQdTwGJYDAdaR5cAdlxnq+yEtXI=", + "lastModified": 1717336170, + "narHash": "sha256-hkD00+n53WNZ4k8hqIbekl5WGDsmb5urhAuDh5XYjyc=", "owner": "nixos", "repo": "nixpkgs", - "rev": "ab5efd0f3c62dd3b75d21d0de1dd63efc76be5d8", + "rev": "73bff846b4e8d0c8156c6fc726bf623fe3f3845c", "type": "github" }, "original": { @@ -56,11 +56,11 @@ }, "nixpkgs-stable-for-tests": { "locked": { - "lastModified": 1716991068, - "narHash": "sha256-Av0UWCCiIGJxsZ6TFc+OiKCJNqwoxMNVYDBChmhjNpo=", + "lastModified": 1717159533, + "narHash": "sha256-oamiKNfr2MS6yH64rUn99mIZjc45nGJlj9eGth/3Xuw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "25cf937a30bf0801447f6bf544fc7486c6309234", + "rev": "a62e6edd6d5e1fa0329b8653c801147986f8d446", "type": "github" }, "original": { @@ -89,11 +89,11 @@ ] }, "locked": { - "lastModified": 1717208326, - "narHash": "sha256-4gVhbC+NjSQ4c6cJvJGNCI1oTcD+8jRRNAnOF9faGCE=", + "lastModified": 1717294752, + "narHash": "sha256-QhlS52cEQyx+iVcgrEoCnEEpWUA6uLdmeLRxk935inI=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "ab69b67fac9a96709fbef0b899db308ca714a120", + "rev": "b46857a406d207a1de74e792ef3b83e800c30e08", "type": "github" }, "original": { --- a/pkgs/fleet.nix +++ b/pkgs/fleet.nix @@ -1,4 +1,7 @@ -{craneLib}: +{ + craneLib, + installShellFiles, +}: craneLib.buildPackage rec { pname = "fleet"; @@ -7,10 +10,12 @@ cargoExtraArgs = "--locked -p ${pname}"; + nativeBuildInputs = [installShellFiles]; + postInstall = '' for shell in bash fish zsh; do installShellCompletion --cmd fleet \ - --$shell <($out/bin/fleet complete --shell $shell --print) + --$shell <($out/bin/fleet complete --shell $shell) done ''; } -- gitstuff