Add status cli command
This commit is contained in:
parent
1ed5e5d600
commit
427dce3e48
3 changed files with 26 additions and 1 deletions
|
|
@ -3,16 +3,19 @@ use clap::Parser;
|
||||||
use crate::Environment;
|
use crate::Environment;
|
||||||
|
|
||||||
mod migrate;
|
mod migrate;
|
||||||
|
mod status;
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
Migrate(migrate::Command),
|
Migrate(migrate::Command),
|
||||||
|
Status(status::Command),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Self::Migrate(command) => command.run(env),
|
Self::Migrate(command) => command.run(env),
|
||||||
|
Self::Status(command) => command.run(env),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
gdn-cli/src/commands/status.rs
Normal file
22
gdn-cli/src/commands/status.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
use crate::Environment;
|
||||||
|
|
||||||
|
/// Display current status.
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
pub struct Command {}
|
||||||
|
|
||||||
|
impl Command {
|
||||||
|
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||||
|
let data_dir = gdn::data::open(env.data_dir.clone())?;
|
||||||
|
println!("Data dir version: {}", gdn::data::VERSION);
|
||||||
|
|
||||||
|
let state = gdn::data::load_state(&data_dir)?;
|
||||||
|
match state.name {
|
||||||
|
Some(name) => println!("Name: {name}"),
|
||||||
|
None => println!("No name"),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ mod v1;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
datadir::{LockedDataDir, UnlockedDataDir},
|
datadir::{LockedDataDir, UnlockedDataDir},
|
||||||
v1::{VERSION, load_state, save_state},
|
v1::{State, VERSION, load_state, save_state},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn migrate(dir: &LockedDataDir) -> anyhow::Result<()> {
|
fn migrate(dir: &LockedDataDir) -> anyhow::Result<()> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue