-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from blocklessnetwork/cli-refactor-clap
Cli refactor clap
- Loading branch information
Showing
8 changed files
with
197 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
use crate::error::UtilError; | ||
use blockless_car::utils::archive_local; | ||
use std::path::Path; | ||
|
||
use crate::error::UtilError; | ||
#[derive(Debug, clap::Parser)] | ||
pub struct ArchiveCommand { | ||
#[clap(short, help = "the car file for archive.")] | ||
car: String, | ||
|
||
#[clap(short, help = "the source directory to be archived.")] | ||
source: String, | ||
} | ||
|
||
/// archive the local file system to car file | ||
/// `target` is the car file | ||
/// `source` is the directory where the archive is prepared. | ||
pub(crate) fn archive_local_fs( | ||
target: impl AsRef<Path>, | ||
source: impl AsRef<Path>, | ||
) -> Result<(), UtilError> { | ||
let target = target.as_ref(); | ||
let file = std::fs::File::create(target).unwrap(); | ||
archive_local(source, file)?; | ||
Ok(()) | ||
impl ArchiveCommand { | ||
/// archive the local file system to car file | ||
/// `target` is the car file | ||
/// `source` is the directory where the archive is prepared. | ||
pub(crate) fn execute(&self) -> Result<(), UtilError> { | ||
let file = std::fs::File::create(self.car.as_ref() as &Path).unwrap(); // todo handle error | ||
archive_local(self.source.as_ref() as &Path, file)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
use std::{path::Path, fs::File}; | ||
|
||
use crate::error::UtilError; | ||
use blockless_car::reader as car_reader; | ||
use std::{fs::File, path::Path}; | ||
|
||
#[derive(Debug, clap::Parser)] | ||
pub struct CatCommand { | ||
#[clap(help = "the car file to cat.")] | ||
car: String, | ||
|
||
#[clap(short, help = "the cid of content to cat.")] | ||
cid: String, | ||
} | ||
|
||
pub(crate) fn cat_content(path: impl AsRef<Path>, cid: &str) -> Result<(), UtilError> { | ||
let path = path.as_ref(); | ||
if !path.exists() { | ||
return Err(UtilError::new(format!( | ||
"car file [{}] is not exist.", | ||
path.to_str().unwrap() | ||
))); | ||
impl CatCommand { | ||
pub(crate) fn execute(&self) -> Result<(), UtilError> { | ||
let path: &Path = self.car.as_ref(); | ||
if !path.exists() { | ||
return Err(UtilError::new(format!( | ||
"the car file [{}] does not exist.", | ||
self.car | ||
))); | ||
} | ||
let file = File::open(path)?; | ||
let mut reader = car_reader::new_v1(file)?; | ||
blockless_car::utils::cat_ipld_str(&mut reader, &self.cid)?; | ||
Ok(()) | ||
} | ||
let file = File::open(path)?; | ||
let mut reader = car_reader::new_v1(file)?; | ||
blockless_car::utils::cat_ipld_str(&mut reader, cid)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.