chore: update README
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
use std::error::Error;
|
||||
|
||||
use crate::usb;
|
||||
|
||||
use super::common::file::{Input, Output};
|
||||
@@ -22,35 +20,32 @@ pub enum BackupCmd {
|
||||
},
|
||||
}
|
||||
|
||||
fn handle_export(
|
||||
device_id: Option<&str>,
|
||||
output: Output,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
fn handle_export(device_id: Option<&str>, output: &Output) -> Result<(), anyhow::Error> {
|
||||
let camera = usb::get_camera(device_id)?;
|
||||
let mut ptp = camera.ptp_session()?;
|
||||
|
||||
let mut writer = output.get_writer()?;
|
||||
|
||||
todo!();
|
||||
let backup = camera.export_backup(&mut ptp)?;
|
||||
writer.write_all(&backup)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_import(
|
||||
device_id: Option<&str>,
|
||||
input: Input,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
fn handle_import(device_id: Option<&str>, input: &Input) -> Result<(), anyhow::Error> {
|
||||
let camera = usb::get_camera(device_id)?;
|
||||
let mut ptp = camera.ptp_session()?;
|
||||
|
||||
let mut reader = input.get_reader()?;
|
||||
|
||||
todo!();
|
||||
let mut buffer = Vec::new();
|
||||
reader.read_to_end(&mut buffer)?;
|
||||
camera.import_backup(&mut ptp, &buffer)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle(cmd: BackupCmd, device_id: Option<&str>) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
pub fn handle(cmd: BackupCmd, device_id: Option<&str>) -> Result<(), anyhow::Error> {
|
||||
match cmd {
|
||||
BackupCmd::Export { output_file } => handle_export(device_id, output_file),
|
||||
BackupCmd::Import { input_file } => handle_import(device_id, input_file),
|
||||
BackupCmd::Export { output_file } => handle_export(device_id, &output_file),
|
||||
BackupCmd::Import { input_file } => handle_import(device_id, &input_file),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{error::Error, fs::File, io, path::PathBuf, str::FromStr};
|
||||
use std::{fs::File, io, path::PathBuf, str::FromStr};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Input {
|
||||
@@ -7,21 +7,21 @@ pub enum Input {
|
||||
}
|
||||
|
||||
impl FromStr for Input {
|
||||
type Err = Box<dyn Error + Send + Sync>;
|
||||
type Err = anyhow::Error;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
if s == "-" {
|
||||
Ok(Input::Stdin)
|
||||
Ok(Self::Stdin)
|
||||
} else {
|
||||
Ok(Input::Path(PathBuf::from(s)))
|
||||
Ok(Self::Path(PathBuf::from(s)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Input {
|
||||
pub fn get_reader(&self) -> Result<Box<dyn io::Read>, Box<dyn Error + Send + Sync>> {
|
||||
pub fn get_reader(&self) -> Result<Box<dyn io::Read>, anyhow::Error> {
|
||||
match self {
|
||||
Input::Stdin => Ok(Box::new(io::stdin())),
|
||||
Input::Path(path) => Ok(Box::new(File::open(path)?)),
|
||||
Self::Stdin => Ok(Box::new(io::stdin())),
|
||||
Self::Path(path) => Ok(Box::new(File::open(path)?)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,21 +33,21 @@ pub enum Output {
|
||||
}
|
||||
|
||||
impl FromStr for Output {
|
||||
type Err = Box<dyn Error + Send + Sync>;
|
||||
type Err = anyhow::Error;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
if s == "-" {
|
||||
Ok(Output::Stdout)
|
||||
Ok(Self::Stdout)
|
||||
} else {
|
||||
Ok(Output::Path(PathBuf::from(s)))
|
||||
Ok(Self::Path(PathBuf::from(s)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Output {
|
||||
pub fn get_writer(&self) -> Result<Box<dyn io::Write>, Box<dyn Error + Send + Sync>> {
|
||||
pub fn get_writer(&self) -> Result<Box<dyn io::Write>, anyhow::Error> {
|
||||
match self {
|
||||
Output::Stdout => Ok(Box::new(io::stdout())),
|
||||
Output::Path(path) => Ok(Box::new(File::create(path)?)),
|
||||
Self::Stdout => Ok(Box::new(io::stdout())),
|
||||
Self::Path(path) => Ok(Box::new(File::create(path)?)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::error::Error;
|
||||
|
||||
use anyhow::bail;
|
||||
use clap::Args;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -9,18 +8,18 @@ pub enum SimulationSelector {
|
||||
}
|
||||
|
||||
impl std::str::FromStr for SimulationSelector {
|
||||
type Err = Box<dyn Error + Send + Sync>;
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
if let Ok(slot) = s.parse::<u8>() {
|
||||
return Ok(SimulationSelector::Slot(slot));
|
||||
return Ok(Self::Slot(slot));
|
||||
}
|
||||
|
||||
if s.is_empty() {
|
||||
Err("Simulation name cannot be empty".into())
|
||||
} else {
|
||||
Ok(SimulationSelector::Name(s.to_string()))
|
||||
bail!("Simulation name cannot be empty")
|
||||
}
|
||||
|
||||
Ok(Self::Name(s.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use std::{error::Error, fmt};
|
||||
use std::fmt;
|
||||
|
||||
use clap::Subcommand;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
hardware::{CameraImpl, FujiUsbMode},
|
||||
hardware::{CameraImpl, UsbMode},
|
||||
usb,
|
||||
};
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
#[derive(Subcommand, Debug, Clone, Copy)]
|
||||
pub enum DeviceCmd {
|
||||
/// List cameras
|
||||
#[command(alias = "l")]
|
||||
@@ -29,7 +29,7 @@ pub struct CameraItemRepr {
|
||||
|
||||
impl From<&Box<dyn CameraImpl>> for CameraItemRepr {
|
||||
fn from(camera: &Box<dyn CameraImpl>) -> Self {
|
||||
CameraItemRepr {
|
||||
Self {
|
||||
id: camera.usb_id(),
|
||||
name: camera.id().name.to_string(),
|
||||
vendor_id: format!("0x{:04x}", camera.id().vendor),
|
||||
@@ -48,10 +48,10 @@ impl fmt::Display for CameraItemRepr {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_list(json: bool) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
fn handle_list(json: bool) -> Result<(), anyhow::Error> {
|
||||
let cameras: Vec<CameraItemRepr> = usb::get_connected_camers()?
|
||||
.iter()
|
||||
.map(|d| d.into())
|
||||
.map(std::convert::Into::into)
|
||||
.collect();
|
||||
|
||||
if json {
|
||||
@@ -66,7 +66,7 @@ fn handle_list(json: bool) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
|
||||
println!("Connected cameras:");
|
||||
for d in cameras {
|
||||
println!("- {}", d);
|
||||
println!("- {d}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -81,7 +81,7 @@ pub struct CameraRepr {
|
||||
pub model: String,
|
||||
pub device_version: String,
|
||||
pub serial_number: String,
|
||||
pub mode: FujiUsbMode,
|
||||
pub mode: UsbMode,
|
||||
pub battery: u32,
|
||||
}
|
||||
|
||||
@@ -103,19 +103,22 @@ impl fmt::Display for CameraRepr {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_info(json: bool, device_id: Option<&str>) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
let mut camera = usb::get_camera(device_id)?;
|
||||
fn handle_info(json: bool, device_id: Option<&str>) -> Result<(), anyhow::Error> {
|
||||
let camera = usb::get_camera(device_id)?;
|
||||
let mut ptp = camera.ptp();
|
||||
|
||||
let info = camera.get_info()?;
|
||||
let mode = camera.get_fuji_usb_mode()?;
|
||||
let battery = camera.get_fuji_battery_info()?;
|
||||
let info = camera.get_info(&mut ptp)?;
|
||||
|
||||
let mut ptp = camera.open_session(ptp)?;
|
||||
let mode = camera.get_usb_mode(&mut ptp)?;
|
||||
let battery = camera.get_battery_info(&mut ptp)?;
|
||||
|
||||
let repr = CameraRepr {
|
||||
device: (&camera).into(),
|
||||
manufacturer: info.Manufacturer.clone(),
|
||||
model: info.Model.clone(),
|
||||
device_version: info.DeviceVersion.clone(),
|
||||
serial_number: info.SerialNumber.clone(),
|
||||
serial_number: info.SerialNumber,
|
||||
mode,
|
||||
battery,
|
||||
};
|
||||
@@ -125,15 +128,11 @@ fn handle_info(json: bool, device_id: Option<&str>) -> Result<(), Box<dyn Error
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
println!("{}", repr);
|
||||
println!("{repr}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle(
|
||||
cmd: DeviceCmd,
|
||||
json: bool,
|
||||
device_id: Option<&str>,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
pub fn handle(cmd: DeviceCmd, json: bool, device_id: Option<&str>) -> Result<(), anyhow::Error> {
|
||||
match cmd {
|
||||
DeviceCmd::List => handle_list(json),
|
||||
DeviceCmd::Info => handle_info(json, device_id),
|
||||
|
||||
Reference in New Issue
Block a user