git.delta.rocks / jrsonnet / refs/commits / aac7f3854e2a

difftreelog

fix(fleet-cmd) include the required package for tab completions (#5)

Petr Portnov | PROgrm_JARvis2024-06-02parent: #ad7852d.patch.diff
in: trunk
* fix(fleet-cmd): include the required package for tab completions

* style(fleet-cmd): reformat automatically

9 files changed

modifiedcmds/fleet/src/better_nix_eval.rsdiffbeforeafterboth
1//! Wrapper around nix repl, which allows to work on nix code, without relying on1//! Wrapper around nix repl, which allows to work on nix code, without relying on
2//! nix libexpr. I mean, nix libexpr is good, but until it has no C bindings, this is the royal PITA.2//! nix libexpr. I mean, nix libexpr is good, but until it has no C bindings, this is the royal PITA.
33
4use std::collections::HashMap;4use std::{
5use std::ffi::{OsStr, OsString};5 collections::HashMap,
6use std::fmt::{self, Display};6 ffi::{OsStr, OsString},
7 fmt::{self, Display},
7use std::path::PathBuf;8 path::PathBuf,
8use std::process::Stdio;9 process::Stdio,
9use std::sync::{Arc, OnceLock};10 sync::{Arc, OnceLock},
11};
1012
11use anyhow::{anyhow, bail, ensure, Context, Result};13use anyhow::{anyhow, bail, ensure, Context, Result};
12use better_command::{ClonableHandler, Handler, NixHandler, NoopHandler};14use better_command::{ClonableHandler, Handler, NixHandler, NoopHandler};
13use futures::StreamExt;15use futures::StreamExt;
14use itertools::Itertools;16use itertools::Itertools;
15use serde::de::DeserializeOwned;
16use serde::{Deserialize, Serialize};17use serde::{de::DeserializeOwned, Deserialize, Serialize};
17use tokio::io::AsyncWriteExt;
18use tokio::process::{ChildStderr, ChildStdin, ChildStdout, Command};18use tokio::{
19use tokio::select;19 io::AsyncWriteExt,
20use tokio::sync::{mpsc, oneshot, Mutex};20 process::{ChildStderr, ChildStdin, ChildStdout, Command},
21 select,
22 sync::{mpsc, oneshot, Mutex},
23};
21use tracing::{debug, error, warn, Level};24use tracing::{debug, error, warn, Level};
2225
23
modifiedcmds/fleet/src/cmds/build_systems.rsdiffbeforeafterboth
--- 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
modifiedcmds/fleet/src/cmds/info.rsdiffbeforeafterboth
--- 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)]
modifiedcmds/fleet/src/cmds/mod.rsdiffbeforeafterboth
--- 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;
modifiedcmds/fleet/src/extra_args.rsdiffbeforeafterboth
--- 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<Vec<OsString>> {
 	Ok(shlex::bytes::split(os.as_encoded_bytes())
 		.ok_or_else(|| anyhow!("invalid arguments"))?
modifiedcmds/fleet/src/keys.rsdiffbeforeafterboth
--- 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<String> {
 		let data = self.data();
modifiedcmds/fleet/src/main.rsdiffbeforeafterboth
--- 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 {
modifiedflake.lockdiffbeforeafterboth
--- 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": {
modifiedpkgs/fleet.nixdiffbeforeafterboth
--- 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
   '';
 }