Skip to content

Commit

Permalink
fix proxy manner
Browse files Browse the repository at this point in the history
  • Loading branch information
koushiro committed Oct 23, 2024
1 parent 60680ec commit baeb5fd
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 21 deletions.
16 changes: 0 additions & 16 deletions bin/oli/src/bin/oli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,19 @@
use std::env;
use std::ffi::OsStr;
use std::ffi::OsString;
use std::path::PathBuf;

use anyhow::anyhow;
use anyhow::Result;
use clap::value_parser;
use oli::commands::OliSubcommand;

#[derive(Debug, clap::Parser)]
#[command(about, version)]
pub struct Oli {
/// Path to the config file.
#[arg(
long,
global = true,
default_value = default_config_path(),
value_parser = value_parser!(PathBuf)
)]
config: Option<PathBuf>,

#[command(subcommand)]
subcommand: OliSubcommand,
}

fn default_config_path() -> OsString {
let d = dirs::config_dir().expect("unknown config dir");
d.join("oli/config.toml").as_os_str().to_owned()
}

#[tokio::main]
async fn main() -> Result<()> {
// Guard against infinite proxy recursion. This mostly happens due to
Expand Down
7 changes: 6 additions & 1 deletion bin/oli/src/commands/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::path::PathBuf;
use anyhow::Result;
use futures::io;

use crate::commands::default_config_path;
use crate::config::Config;

#[derive(Debug, clap::Parser)]
Expand All @@ -30,7 +31,11 @@ use crate::config::Config;
)]
pub struct CatCmd {
/// Path to the config file.
#[arg(from_global)]
#[arg(
long,
default_value = default_config_path(),
value_parser = clap::value_parser!(PathBuf)
)]
pub config: PathBuf,
#[arg()]
pub target: String,
Expand Down
7 changes: 6 additions & 1 deletion bin/oli/src/commands/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ use anyhow::Result;
use futures::AsyncWriteExt;
use futures::TryStreamExt;

use crate::commands::default_config_path;
use crate::config::Config;

#[derive(Debug, clap::Parser)]
#[command(name = "cp", about = "Copy object", disable_version_flag = true)]
pub struct CopyCmd {
/// Path to the config file.
#[arg(from_global)]
#[arg(
long,
default_value = default_config_path(),
value_parser = clap::value_parser!(PathBuf)
)]
pub config: PathBuf,
#[arg()]
pub source: String,
Expand Down
7 changes: 6 additions & 1 deletion bin/oli/src/commands/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ use std::path::PathBuf;
use anyhow::Result;
use futures::TryStreamExt;

use crate::commands::default_config_path;
use crate::config::Config;

#[derive(Debug, clap::Parser)]
#[command(name = "ls", about = "List object", disable_version_flag = true)]
pub struct LsCmd {
/// Path to the config file.
#[arg(from_global)]
#[arg(
long,
default_value = default_config_path(),
value_parser = clap::value_parser!(PathBuf)
)]
pub config: PathBuf,
#[arg()]
pub target: String,
Expand Down
7 changes: 7 additions & 0 deletions bin/oli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@

//! Commands provides the implementation of each command.
use std::ffi::OsString;

pub mod cat;
pub mod cp;
pub mod ls;
pub mod rm;
pub mod stat;

fn default_config_path() -> OsString {
let d = dirs::config_dir().expect("unknown config dir");
d.join("oli/config.toml").as_os_str().to_owned()
}

#[derive(Debug, clap::Subcommand)]
pub enum OliSubcommand {
Cat(cat::CatCmd),
Expand Down
7 changes: 6 additions & 1 deletion bin/oli/src/commands/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ use std::path::PathBuf;

use anyhow::Result;

use crate::commands::default_config_path;
use crate::config::Config;

#[derive(Debug, clap::Parser)]
#[command(name = "rm", about = "Remove object", disable_version_flag = true)]
pub struct RmCmd {
/// Path to the config file.
#[arg(from_global)]
#[arg(
long,
default_value = default_config_path(),
value_parser = clap::value_parser!(PathBuf)
)]
pub config: PathBuf,
#[arg()]
pub target: String,
Expand Down
7 changes: 6 additions & 1 deletion bin/oli/src/commands/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::path::PathBuf;

use anyhow::Result;

use crate::commands::default_config_path;
use crate::config::Config;

#[derive(Debug, clap::Parser)]
Expand All @@ -29,7 +30,11 @@ use crate::config::Config;
)]
pub struct StatCmd {
/// Path to the config file.
#[arg(from_global)]
#[arg(
long,
default_value = default_config_path(),
value_parser = clap::value_parser!(PathBuf)
)]
pub config: PathBuf,
#[arg()]
pub target: String,
Expand Down

0 comments on commit baeb5fd

Please sign in to comment.