Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.66"
bs58 = "0.4.0"
base64 = "0.13.0"
clap = { version = "3.2.12", features = ["derive"] }
Expand Down
220 changes: 203 additions & 17 deletions src/cmd/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::legacy::{prepare_args, prepare_flags};
use anyhow::Result;
use clap::{ArgEnum, Args, Subcommand};
use std::{collections::HashMap, process::Command};

#[derive(Args)]
pub struct App {
Expand All @@ -10,39 +13,119 @@ pub struct App {
pub enum AppCommands {
#[clap(about = "Delegate capability to an audience DID")]
Delegate {
#[clap(short, long, value_parser, help = "The target app")]
#[clap(short, long, value_name = "NAME", help = "The target app")]
app_name: Option<String>,
#[clap(short, long, value_parser, help = "An audience DID")]
#[clap(short, long, help = "An audience DID")]
did: Option<String>,
#[clap(
short,
long,
arg_enum,
value_parser,
value_enum,
default_value = "append",
help = "The potency to delegate"
)]
potency: Potency,
#[clap(
short,
long,
value_parser,
default_value_t = 300,
help = "Lifetime in seconds before UCAN expires"
)]
lifetime: u16,
#[clap(short, long, help = "Only output the UCAN on success")]
quiet: bool,
#[clap(from_global)]
verbose: bool,
#[clap(from_global)]
remote: Option<String>,
},
#[clap(about = "Detail about the current app")]
Info {
#[clap(from_global)]
verbose: bool,
#[clap(from_global)]
remote: Option<String>,
},
#[clap(about = "Upload the working directory")]
Publish {
#[clap(
help = "The file path of the assets or directory to sync",
default_value = "./"
)]
path: String,
#[clap(short, long, help = "Open your default browser after publish")]
open: bool,
#[clap(short, long, help = "Watch for changes & automatically trigger upload")]
watch: bool,
#[clap(
long = "ipfs-bin",
help = "Path to IPFS binary [default: `which ipfs`]",
value_name = "BIN_PATH"
)]
ipfs_bin: Option<String>,
#[clap(
long = "ipfs-timeout",
help = "IPFS timeout",
default_value = "1800",
value_name = "SECONDS"
)]
ipfs_timeout: String,
#[clap(
long = "update-data",
help = "Upload the data",
default_value = "True",
value_name = "ARG"
)]
update_data: String,
#[clap(
long = "update-dns",
help = "Update DNS",
default_value = "True",
value_name = "ARG"
)]
update_dns: String,
#[clap(from_global)]
verbose: bool,
#[clap(from_global)]
remote: Option<String>,
},
#[clap(about = "Initialize an existing app")]
Register,
Register {
#[clap(
short,
long = "app-dir",
help = "The file path to initialize the app in (app config, etc.)",
default_value = ".",
value_name = "PATH"
)]
app_dir: String,
#[clap(
short,
long = "build-dir",
help = "The file path of the assets or directory to sync",
value_name = "PATH"
)]
build_dir: Option<String>,
#[clap(short, long = "name", help = "Optional app name")]
name: Option<String>,
#[clap(
long = "ipfs-bin",
help = "Path to IPFS binary [default: `which ipfs`]",
value_name = "BIN_PATH"
)]
ipfs_bin: Option<String>,
#[clap(
long = "ipfs-timeout",
help = "IPFS timeout",
default_value = "1800",
value_name = "SECONDS"
)]
ipfs_timeout: String,
#[clap(from_global)]
verbose: bool,
#[clap(from_global)]
remote: Option<String>,
},
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ArgEnum)]
Expand All @@ -51,22 +134,125 @@ pub enum Potency {
Destroy,
SuperUser,
}
pub fn run_command(a: App) {

impl Potency {
fn to_string(&self) -> String {
match self {
Potency::Append => "Append".to_string(),
Potency::Destroy => "Destroy".to_string(),
Potency::SuperUser => "Super_User".to_string(),
}
}
}

pub fn run_command(a: App) -> Result<()> {
match a.command {
AppCommands::Delegate {
app_name: _,
did: _,
potency: _,
lifetime: _,
quiet: _,
app_name,
did,
lifetime,
potency,
quiet,
verbose,
remote,
} => {
todo!("delegate")
let args = prepare_args(&HashMap::from([
("-a", app_name.as_ref()),
("-d", did.as_ref()),
("-l", Some(lifetime.to_string()).as_ref()),
("-p", Some(potency.to_string()).as_ref()),
]));
let remote = prepare_args(&HashMap::from([("-R", remote.as_ref())]));

// N.B. The wrapped app delegate command does not accept verbose
let flags = prepare_flags(&HashMap::from([("-q", quiet)]));

Command::new("fission")
.args(["app", "delegate"])
.args(args)
.args(remote)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remote arg must come after the other args, but before flags for compatibility with the existing CLI.

.args(flags)
.spawn()?
.wait()?;

Ok(())
}
AppCommands::Publish { open: _, watch: _ } => {
todo!("publish")
AppCommands::Info { verbose, remote } => {
let remote = prepare_args(&HashMap::from([("-R", remote.as_ref())]));
let flags = prepare_flags(&HashMap::from([("-v", verbose)]));

Command::new("fission")
.args(["app", "info"])
.args(remote)
.args(flags)
.spawn()?
.wait()?;

Ok(())
}
AppCommands::Register => {
todo!("register")
AppCommands::Publish {
path,
open,
watch,
ipfs_bin,
ipfs_timeout,
update_data,
update_dns,
verbose,
remote,
} => {
let args = prepare_args(&HashMap::from([
("--ipfs-bin", ipfs_bin.as_ref()),
("--ipfs-timeout", Some(ipfs_timeout).as_ref()),
("--update-data", Some(update_data).as_ref()),
("--update-dns", Some(update_dns).as_ref()),
]));
let remote = prepare_args(&HashMap::from([("-R", remote.as_ref())]));
let flags = prepare_flags(&HashMap::from([
("-o", open),
("-w", watch),
("-v", verbose),
]));

Command::new("fission")
.args(["app", "publish"])
.arg(path)
.args(args)
.args(remote)
.args(flags)
.spawn()?
.wait()?;

Ok(())
}
AppCommands::Register {
app_dir,
build_dir,
name,
ipfs_bin,
ipfs_timeout,
verbose,
remote,
} => {
let args = prepare_args(&HashMap::from([
("-a", Some(app_dir).as_ref()),
("-b", build_dir.as_ref()),
("-n", name.as_ref()),
("--ipfs-bin", ipfs_bin.as_ref()),
("--ipfs-timeout", Some(ipfs_timeout).as_ref()),
]));
let remote = prepare_args(&HashMap::from([("-R", remote.as_ref())]));
let flags = prepare_flags(&HashMap::from([("-v", verbose)]));

Command::new("fission")
.args(["app", "register"])
.args(args)
.args(remote)
.args(flags)
.spawn()?
.wait()?;

Ok(())
}
}
}
31 changes: 29 additions & 2 deletions src/cmd/setup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
use crate::legacy::{prepare_args, prepare_flags};
use anyhow::Result;
use clap::Args;
use std::{collections::HashMap, process::Command};

#[derive(Args)]
struct Setup {}

pub fn run_command(username: Option<String>) {
todo!("setup --username={:?}", username)
pub fn run_command(
username: Option<String>,
email: Option<String>,
keyfile: Option<String>,
os: Option<String>,
verbose: bool,
remote: Option<String>,
) -> Result<()> {
let args = prepare_args(&HashMap::from([
("-u", username.as_ref()),
("-e", email.as_ref()),
("-k", keyfile.as_ref()),
("--os", os.as_ref()),
]));
let remote = prepare_args(&HashMap::from([("-R", remote.as_ref())]));
let flags = prepare_flags(&HashMap::from([("-v", verbose)]));

Command::new("fission")
.arg("setup")
.args(args)
.args(remote)
.args(flags)
.spawn()?
.wait()?;

Ok(())
}
Loading