Skip to content

Commit e7ab733

Browse files
committed
Add puff status command
1 parent ddafffc commit e7ab733

20 files changed

Lines changed: 210 additions & 90 deletions

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ check:
1313
lint:
1414
cargo clippy
1515

16-
fmt:
16+
format:
1717
cargo fmt
1818

19-
fmt-check:
19+
format-check:
2020
cargo fmt --check
2121

2222
run *args:

src/app_init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use anyhow::Result;
21
use crate::config::{app_config::AppConfig, locations::LocationsProvider};
2+
use anyhow::Result;
33
use std::{
44
fs::{self, File},
55
io::Write,
@@ -44,8 +44,8 @@ impl<'a> AppInitializer<'a> {
4444
mod tests {
4545
use std::{fs, path::PathBuf};
4646

47-
use crate::config::locations::LocationsProvider;
4847
use super::AppInitializer;
48+
use crate::config::locations::LocationsProvider;
4949

5050
#[test]
5151
fn init_when_not_initialized_yet_files_get_created() {

src/cli_args.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::path::PathBuf;
21
use clap::{Args, Parser, Subcommand};
2+
use std::path::PathBuf;
33

44
#[derive(Parser)]
55
#[command(
@@ -47,6 +47,9 @@ pub enum Command {
4747
/// Lists all projects known to puff (both associated and unassociated ones)
4848
List(ListSubcommand),
4949

50+
/// Shows the puff status of the current directory
51+
Status,
52+
5053
/// Subcommand for managing projects
5154
Project {
5255
#[command(subcommand)]

src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ pub mod file_forget_command;
33
pub mod init_command;
44
pub mod list_command;
55
pub mod project_forget_command;
6-
6+
pub mod status_command;

src/commands/add_command.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::{
2-
config::locations::LocationsProvider,
3-
fs_utils::symlink_file,
4-
git_ignore::{GitIgnoreHandler, GitIgnoreResult},
2+
config::locations::LocationsProvider, fs_utils::symlink_file, git_ignore::GitIgnoreHandler,
53
};
64
use anyhow::{Result, anyhow, bail};
75
use std::{

src/commands/file_forget_command.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ use std::{
44
path::{Path, PathBuf},
55
};
66

7-
use crate::{
8-
config::locations::LocationsProvider,
9-
fs_utils::is_symlink,
10-
};
7+
use crate::{config::locations::LocationsProvider, fs_utils::is_symlink};
118

129
pub struct ForgetCommand<'a> {
1310
locations_provider: &'a LocationsProvider,
@@ -39,7 +36,8 @@ impl<'a> ForgetCommand<'a> {
3936
.parent()
4037
.ok_or_else(|| anyhow!("Could not retrieve user's project directory"))?;
4138

42-
let (project_name, project_root) = self.locations_provider.find_project_for_path(user_dir)?;
39+
let (project_name, project_root) =
40+
self.locations_provider.find_project_for_path(user_dir)?;
4341
let relative_path = user_file.strip_prefix(&project_root)?;
4442

4543
if !self.is_file_added(&project_name, relative_path)? {

src/commands/init_command.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use anyhow::{bail, Result};
21
use crate::{
32
config::{
43
app_config::AppConfigManager, locations::LocationsProvider, projects::ProjectsRetriever,
54
},
65
project_init::existing::ExistingProjectInitializer,
76
};
7+
use anyhow::{Result, bail};
88
use std::{fs, path::Path};
99

1010
pub struct InitCommand<'a> {
@@ -44,11 +44,7 @@ impl<'a> InitCommand<'a> {
4444
Ok(())
4545
}
4646

47-
fn handle_with_unassociated(
48-
&self,
49-
unassociated: Vec<String>,
50-
cwd: &Path,
51-
) -> Result<()> {
47+
fn handle_with_unassociated(&self, unassociated: Vec<String>, cwd: &Path) -> Result<()> {
5248
println!("Some projects in puff are not yet associated with a path on this machine.");
5349
println!("Associate one with the current directory, or create a new project.");
5450
let choice = self.ask_about_unassociated(&unassociated)?;
@@ -98,10 +94,7 @@ impl<'a> InitCommand<'a> {
9894
}
9995
}
10096

101-
fn ask_about_unassociated(
102-
&self,
103-
unassociated: &'a [String],
104-
) -> Result<UserChoice<'a>> {
97+
fn ask_about_unassociated(&self, unassociated: &'a [String]) -> Result<UserChoice<'a>> {
10598
println!("0) Create a new project");
10699
for (i, project) in unassociated.iter().enumerate() {
107100
println!("{}) Associate with the project '{}'", i + 1, project);
@@ -123,7 +116,10 @@ impl<'a> InitCommand<'a> {
123116
}
124117
}
125118

126-
println!("Unrecognized option '{}'. Choose from the list below, or press Ctrl+C to cancel.", choice.trim());
119+
println!(
120+
"Unrecognized option '{}'. Choose from the list below, or press Ctrl+C to cancel.",
121+
choice.trim()
122+
);
127123

128124
self.ask_about_unassociated(unassociated)
129125
}

src/commands/list_command.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{bail, Result};
1+
use anyhow::{Result, bail};
22

33
use crate::config::projects::ProjectsRetriever;
44

@@ -11,13 +11,11 @@ impl<'a> ListCommand<'a> {
1111
ListCommand { projects_retriever }
1212
}
1313

14-
pub fn list(
15-
&self,
16-
only_associated: bool,
17-
only_unassociated: bool,
18-
) -> Result<()> {
14+
pub fn list(&self, only_associated: bool, only_unassociated: bool) -> Result<()> {
1915
if only_associated && only_unassociated {
20-
bail!("Flags --only-associated (-a) and --only-unassociated (-u) are mutually exclusive.");
16+
bail!(
17+
"Flags --only-associated (-a) and --only-unassociated (-u) are mutually exclusive."
18+
);
2119
}
2220

2321
let mut print_newline = false;

src/commands/project_forget_command.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ impl<'a> ProjectForgetCommand<'a> {
6262
if delete_files || project_details.files.is_empty() {
6363
println!("Project '{name}' removed.");
6464
} else {
65-
println!("Project '{name}' removed. Managed files have been restored to the project directory.");
65+
println!(
66+
"Project '{name}' removed. Managed files have been restored to the project directory."
67+
);
6668
}
6769
Ok(())
6870
}

src/commands/status_command.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use anyhow::Result;
2+
use std::path::Path;
3+
4+
use crate::config::{locations::LocationsProvider, projects::ProjectsRetriever};
5+
6+
pub struct StatusCommand<'a> {
7+
locations_provider: &'a LocationsProvider,
8+
projects_retriever: &'a ProjectsRetriever<'a>,
9+
}
10+
11+
impl<'a> StatusCommand<'a> {
12+
pub fn new(
13+
locations_provider: &'a LocationsProvider,
14+
projects_retriever: &'a ProjectsRetriever<'a>,
15+
) -> Self {
16+
StatusCommand {
17+
locations_provider,
18+
projects_retriever,
19+
}
20+
}
21+
22+
pub fn status(&self, cwd: &Path) -> Result<()> {
23+
let project = self.locations_provider.find_project_for_path(cwd);
24+
25+
match project {
26+
Err(_) => {
27+
println!("Current directory is not managed by any puff project.");
28+
}
29+
Ok((project_name, _)) => {
30+
let Some(details) = self.projects_retriever.get_details(&project_name)? else {
31+
println!("Current directory is not managed by any puff project.");
32+
return Ok(());
33+
};
34+
35+
println!("Project: {}", details.name);
36+
println!("Managed files:");
37+
if details.files.is_empty() {
38+
println!(" (none)");
39+
} else {
40+
for file in &details.files {
41+
println!(" {}", file.display());
42+
}
43+
}
44+
}
45+
}
46+
47+
Ok(())
48+
}
49+
}

0 commit comments

Comments
 (0)