update docs & Cargo.toml

This commit is contained in:
qwjyh 2024-03-17 03:25:44 +09:00
parent 0e8bd6b4c7
commit f5fe3d6580
12 changed files with 50 additions and 32 deletions

View file

@ -1,7 +1,12 @@
[package] [package]
name = "xdbm" name = "xdbm"
version = "0.1.0" version = "0.1.0"
authors = ["qwjyh <urataw421@gmail.com>"]
edition = "2021" edition = "2021"
description = "Cross device backup manager, to manage backups on several storages mounted on multiple devices."
homepage = "https://github.com/qwjyh/xdbm"
repository = "https://github.com/qwjyh/xdbm"
license = "MIT OR Apache-1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,4 +1,15 @@
# TODO: # xdbm
_Cross device backup manager_,
to manage backups on several storages mounted on multiple devices with a single repository.
## Usage
1. `xdbm init` to setup new device(i.e. PC).
2. `xdbm storage add` to add storages, or `xdbm storage bind` to make existing storages available on new device.
3. `xdbm backup add` to add new backup configuration.
4. `xdbm backup done` to tell xdbm to write backup execution datetime.
5. `xdbm storage list` and `xdbm backup list` to see their status.
## TODO:
- [x] split subcommands to functions - [x] split subcommands to functions
- [x] write test for init subcommand - [x] write test for init subcommand
- [x] write test with existing repo - [x] write test with existing repo

View file

@ -1,3 +1,6 @@
//! Backup config and its history.
//!
use core::panic; use core::panic;
use std::{ use std::{
collections::HashMap, collections::HashMap,
@ -11,7 +14,7 @@ use serde::{Deserialize, Serialize};
use crate::{ use crate::{
devices::Device, devices::Device,
storages::{self, Storage, StorageExt, Storages}, storages::{StorageExt, Storages},
}; };
/// Directory to store backup configs for each devices. /// Directory to store backup configs for each devices.
@ -26,7 +29,7 @@ pub fn backups_file(device: &Device) -> PathBuf {
/// Targets for backup source or destination. /// Targets for backup source or destination.
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct BackupTarget { pub struct BackupTarget {
/// `name()` of [`Storage`]. /// `name()` of [`crate::storages::Storage`].
/// Use `String` for serialization/deserialization. /// Use `String` for serialization/deserialization.
pub storage: String, pub storage: String,
/// Relative path to the `storage`. /// Relative path to the `storage`.

View file

@ -1,7 +1,7 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
io::{self, stdout, Write}, io::{self, stdout, Write},
path::{self, PathBuf}, path::{ PathBuf},
}; };
use anyhow::{anyhow, Context, Ok, Result}; use anyhow::{anyhow, Context, Ok, Result};

View file

@ -1,7 +1,7 @@
//! Init subcommand. //! Init subcommand.
//! Initialize xdbm for the device. //! Initialize xdbm for the device.
use crate::backups::{backups_file, Backups}; use crate::backups::Backups;
use crate::storages::{Storages, STORAGESFILE}; use crate::storages::{Storages, STORAGESFILE};
use crate::{ use crate::{
add_and_commit, backups, full_status, get_devices, write_devices, Device, DEVICESFILE, add_and_commit, backups, full_status, get_devices, write_devices, Device, DEVICESFILE,

View file

@ -14,13 +14,12 @@ use unicode_width::{self, UnicodeWidthStr};
use crate::{ use crate::{
add_and_commit, add_and_commit,
cmd_args::{Cli, StorageAddCommands}, cmd_args::StorageAddCommands,
devices::{self, Device}, devices::{self, Device},
inquire_filepath_completer::FilePathCompleter,
storages::{ storages::{
self, directory, local_info, self, directory, local_info,
physical_drive_partition::{self, PhysicalDrivePartition}, physical_drive_partition::{self, PhysicalDrivePartition},
Storage, StorageExt, StorageType, Storages, Storage, StorageExt, Storages,
}, },
util, util,
}; };

View file

@ -1,29 +1,28 @@
//! # Main types //! # Main types
//! * [Device]: represents PC. module [devices] //! * [Device]: represents PC. module [devices]
//! * [Storage]: all storages. module [storages] //! * [storages::Storage]: all storages. module [storages]
//! * [physical_drive_partition::PhysicalDrivePartition]: partition on a physical disk. module [storages::physical_drive_partition] //! * [storages::physical_drive_partition::PhysicalDrivePartition]: partition on a physical disk. module [storages::physical_drive_partition]
//! * [directory::Directory]: sub-directory of other storages. module [storages::directory] //! * [storages::directory::Directory]: sub-directory of other storages. module [storages::directory]
//! * [online_storage::OnlineStorage]: online storage like Google Drive. module [storages::online_storage] //! * [storages::online_storage::OnlineStorage]: online storage like Google Drive. module [storages::online_storage]
//! * [storages::local_info::LocalInfo]: stores [Device] specific common data for [Storage]s. //! * [storages::Storages] for list of [storages::Storage]
//! //! * [storages::local_info::LocalInfo]: stores [Device] specific common data for [storages::Storage]s.
//! * [backups::Backup] for backup configuration and its logs.
//! * [backups::BackupTarget] source and destination
//! * [backups::BackupLog] backup log
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate dirs; extern crate dirs;
use anyhow::{anyhow, Context, Result}; use anyhow::{Context, Result};
use clap::{CommandFactory, Parser}; use clap::Parser;
use git2::{Commit, Oid, Repository}; use git2::{Commit, Oid, Repository};
use std::path::Path; use std::path::Path;
use std::path::{self, PathBuf}; use std::path::{self, PathBuf};
use storages::Storages; use storages::Storages;
use crate::cmd_args::{BackupSubCommands, Cli, Commands, StorageCommands}; use crate::cmd_args::{BackupSubCommands, Cli, Commands, StorageCommands};
use crate::storages::{
directory, local_info, online_storage, physical_drive_partition, Storage, StorageExt,
StorageType, STORAGESFILE,
};
use devices::{Device, DEVICESFILE, *}; use devices::{Device, DEVICESFILE, *};
mod backups; mod backups;

View file

@ -1,9 +1,10 @@
//! Manipulates storages. //! Manipulates storages.
use crate::storages::directory::Directory; use crate::devices;
use crate::storages::online_storage::OnlineStorage; use crate::storages::{
use crate::storages::physical_drive_partition::PhysicalDrivePartition; directory::Directory, online_storage::OnlineStorage,
use crate::{devices, storages}; physical_drive_partition::PhysicalDrivePartition,
};
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use clap::ValueEnum; use clap::ValueEnum;
use core::panic; use core::panic;

View file

@ -1,7 +1,7 @@
//! Device specific common data for storages. //! Device specific common data for storages.
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::{self, PathBuf}; use std::path::PathBuf;
/// Store local (device-specific) information /// Store local (device-specific) information
/// ///
@ -10,11 +10,11 @@ use std::path::{self, PathBuf};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct LocalInfo { pub struct LocalInfo {
alias: String, alias: String,
mount_path: path::PathBuf, mount_path: PathBuf,
} }
impl LocalInfo { impl LocalInfo {
pub fn new(alias: String, mount_path: path::PathBuf) -> LocalInfo { pub fn new(alias: String, mount_path: PathBuf) -> LocalInfo {
LocalInfo { alias, mount_path } LocalInfo { alias, mount_path }
} }
@ -22,7 +22,7 @@ impl LocalInfo {
self.alias.clone() // ? self.alias.clone() // ?
} }
pub fn mount_path(&self) -> path::PathBuf { pub fn mount_path(&self) -> PathBuf {
self.mount_path.clone() self.mount_path.clone()
} }
} }

View file

@ -87,7 +87,7 @@ impl StorageExt for OnlineStorage {
Ok(()) Ok(())
} }
fn parent(&self, storages: &Storages) -> Option<&Storage> { fn parent(&self, _storages: &Storages) -> Option<&Storage> {
None None
} }
} }

View file

@ -165,7 +165,7 @@ impl StorageExt for PhysicalDrivePartition {
Ok(()) Ok(())
} }
fn parent(&self, storages: &Storages) -> Option<&Storage> { fn parent(&self, _storages: &Storages) -> Option<&Storage> {
None None
} }
} }

View file

@ -1,8 +1,8 @@
mod cmd_init { mod cmd_init {
use std::fs::DirBuilder; use std::fs::DirBuilder;
use anyhow::{anyhow, Ok, Result}; use anyhow::{Ok, Result};
use assert_cmd::{assert::OutputAssertExt, cargo::CommandCargoExt, Command}; use assert_cmd::{assert::OutputAssertExt, Command};
use git2::Repository; use git2::Repository;
use log::trace; use log::trace;
use predicates::prelude::predicate; use predicates::prelude::predicate;