Skip to content

Commit

Permalink
- enhance: fav -d /path to set working directory.
Browse files Browse the repository at this point in the history
- enhance: `fav auth reuse` can receive path both containing or not containing `.fav`.
- enhance: add a systemd service example in README.
  • Loading branch information
kingwingfly committed Nov 10, 2024
1 parent fcbe41f commit b97823b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
-->

## [Unreleased]
## [0.2.35] - 2024-11-10

- enhance: `fav -d /path` to set working directory.
- enhance: `fav auth reuse` can receive path both containing or not containing `.fav`.
- enhance: add a systemd service example in README.

## [0.2.34] - 2024-11-06

- bump dependencies
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace.package]
version = "0.2.34"
version = "0.2.35"
authors = ["Louis <[email protected]>"]
description = "Back up your favorite online resources with CLI."
license = "MIT"
Expand All @@ -14,10 +14,10 @@ repository = "https://github.com/kingwingfly/fav"
documentation = ""

[workspace.dependencies]
fav_core = { path = "fav_core", version = "0.1.5" }
fav_core = { path = "fav_core", version = "0.1.6" }
fav_derive = { path = "fav_derive", version = "0.0.3" }
fav_utils = { path = "fav_utils", version = "0.0.14" }
fav_cli = { path = "fav_cli", version = "0.2.34" }
fav_cli = { path = "fav_cli", version = "0.2.35" }

[profile.release]
lto = "fat"
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ $ fav daemon 30
$ fav status -r | awk -F '' '{print $3}' | grep -v '^\s*$' | sort | uniq -c | sort -n
```

Service example:
```ini
# fav.service
[Unit]
Description=Fav Daemon Service
After=network-online.target

[Service]
Type=simple
User=your_user
WorkingDirectory=/path/to/fav_set
ExecStart=/usr/local/bin/fav daemon 180
Restart=on-failure

[Install]
WantedBy=multi-user.target
```

_For more examples, please refer to the [Documentation](https://github.com/kingwingfly/fav)_

<p align="right">(<a href="#readme-top">back to top</a>)</p>
Expand Down
2 changes: 1 addition & 1 deletion fav_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
fav_core = { workspace = true }
fav_utils = { workspace = true }
# CLI
clap = { version = "4.5", features = ["derive"] }
clap = { version = "4.5", features = ["derive", "string"] }
clap_complete = { version = "4" }
# Async
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
9 changes: 7 additions & 2 deletions fav_cli/src/bili/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use action::*;
use clap::{error::ErrorKind, CommandFactory as _, Parser, Subcommand, ValueHint};
use fav_core::{local::ProtoLocal as _, FavCoreResult};
use fav_utils::bili::BiliSets;
use std::env::{current_dir, set_current_dir};
use tracing::info;

const VERSION: &str = const_format::formatcp!(
Expand All @@ -23,6 +24,8 @@ const VERSION: &str = const_format::formatcp!(
#[derive(Parser)]
#[command(author, version = VERSION, about)]
pub struct Cli {
#[clap(short = 'd', long, default_value = current_dir().unwrap().into_os_string())]
working_dir: std::path::PathBuf,
#[clap(subcommand)]
subcmd: Commands,
}
Expand Down Expand Up @@ -97,7 +100,7 @@ enum AuthCommand {
Logout,
/// Reuse the login info
Reuse {
/// The path of .fav folder, example: /path/to/.fav
/// The path of .fav folder, example: /path/to/dir_containing_`.fav`
#[arg(value_hint = ValueHint::DirPath)]
path: std::path::PathBuf,
},
Expand All @@ -107,6 +110,7 @@ impl Cli {
/// Run the CLI.
pub async fn run() -> FavCoreResult<()> {
let args = Self::parse();
set_current_dir(args.working_dir)?;
match args.subcmd {
Commands::Init => init()?,
Commands::Auth {
Expand All @@ -123,7 +127,8 @@ impl Cli {
match authcmd {
AuthCommand::Login => login().await?,
AuthCommand::Reuse { path } => {
std::fs::hard_link(path.join("bili"), ".fav/bili")?;
std::fs::hard_link(path.join("bili"), ".fav/bili")
.or(std::fs::hard_link(path.join(".fav/bili"), ".fav/bili"))?;
info!("Reuse the login info from {}", path.display());
}
_ => unreachable!(),
Expand Down
2 changes: 1 addition & 1 deletion fav_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fav_core"
version = "0.1.5"
version = "0.1.6"
authors.workspace = true
description = "Fav's core crate; A collection of traits."
license.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions fav_core/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Config,
//! helping managing the configuration
use std::collections::HashMap;

use crate::local::ProtoLocal;
use reqwest::header::{HeaderMap, HeaderValue};
use std::collections::HashMap;

/// A HttpConfig, including headers and cookies.
/// # Example
Expand Down
7 changes: 4 additions & 3 deletions fav_core/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::{ops::Net, res::Res, FavCoreResult};
use core::future::Future;
use protobuf::MessageFull;
use std::path::PathBuf;
use url::Url;

/// Refer to a path on disk;
Expand Down Expand Up @@ -36,7 +37,7 @@ pub trait ProtoLocal: PathInfo + MessageFull {
/// Write the protobuf to file, which is at `PathInfo::PATH`
/// Create the parent directory if not exists
fn write(&self) -> FavCoreResult<()> {
let path = std::path::PathBuf::from(Self::PATH);
let path = PathBuf::from(Self::PATH);
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)?;
}
Expand All @@ -47,14 +48,14 @@ pub trait ProtoLocal: PathInfo + MessageFull {

/// Read the protobuf from file, which is at `PathInfo::PATH`
fn read() -> FavCoreResult<Self> {
let path = std::path::PathBuf::from(Self::PATH);
let path = PathBuf::from(Self::PATH);
let mut file = std::fs::File::open(path)?;
Ok(Self::parse_from_reader(&mut file)?)
}

/// Remove the resource, which is at `PathInfo::PATH`
fn remove() {
let path = std::path::PathBuf::from(Self::PATH);
let path = PathBuf::from(Self::PATH);
std::fs::remove_file(path).ok(); // Just omit the result
}
}
Expand Down

0 comments on commit b97823b

Please sign in to comment.