finish?
This commit is contained in:
parent
9cfb871998
commit
022543445b
|
@ -2,6 +2,152 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "argparse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f8ebf5827e4ac4fd5946560e6a99776ea73b596d80898f357007317a7141e47"
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5f1fea81f183005ced9e59cdb01737ef2423956dac5a6d731b06b2ecfaa3467"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"indexmap",
|
||||
"os_str_bytes",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "intern"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"argparse",
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06e509672465a0504304aa87f9f176f2b2b716ed8fb105ebe5c02dc6dce96a94"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.14.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
|
|
@ -6,3 +6,5 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
argparse = "0.2.2"
|
||||
clap = "3.0.14"
|
||||
|
|
106
src/main.rs
106
src/main.rs
|
@ -3,30 +3,108 @@ const NO_TITLE_ARGUMENT: &str = "Sorry, but you can't provide the --title argume
|
|||
const NO_TITLE_ARGUMENT_2: &str = "Sorry, but you need to provide the --title argument";
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::env::args;
|
||||
use std::collections::HashMap;
|
||||
|
||||
extern crate clap;
|
||||
use clap::{Arg, App, SubCommand};
|
||||
|
||||
fn main() {
|
||||
let arguments_raw = args();
|
||||
let mut args = Vec::new();
|
||||
for arg in arguments_raw {
|
||||
args.push(arg);
|
||||
}
|
||||
let mut identifier = &args[1];
|
||||
let mut title = &args[2];
|
||||
let metadata = match &args[3] {
|
||||
"web" => vec!("mediatype:texts",
|
||||
}
|
||||
let mut identifier = String::new();
|
||||
let mut title = String::new();
|
||||
let matches = App::new("intern")
|
||||
.version("1.0")
|
||||
.author("TheTechRobo")
|
||||
.about("Creates a command for the ia cli")
|
||||
.arg(Arg::with_name("IDENTIFIER")
|
||||
.help("Sets the item identifier")
|
||||
.required(true)
|
||||
.index(1))
|
||||
.arg(Arg::with_name("TITLE")
|
||||
.help("Item title")
|
||||
.required(true)
|
||||
.index(2))
|
||||
.arg(Arg::with_name("TYPE")
|
||||
.help("Type of item (one of: web text wiki)")
|
||||
.required(true)
|
||||
.index(3))
|
||||
.arg(Arg::with_name("metadata")
|
||||
.short('m')
|
||||
.long("metadata")
|
||||
.multiple(true)
|
||||
.takes_value(true)
|
||||
.help("Add Metadata"))
|
||||
.arg(Arg::with_name("options")
|
||||
.short('i')
|
||||
.long("extra-options")
|
||||
.multiple(true)
|
||||
.takes_value(true)
|
||||
.help("Arguments to pass to ia"))
|
||||
.get_matches();
|
||||
let raw_metadata: Vec<&str> = match matches.values_of("metadata") {
|
||||
Some(args) => args.collect(),
|
||||
None => vec!(),
|
||||
};
|
||||
let raw_options: Vec<&str> = match matches.values_of("options") {
|
||||
Some(args) => args.collect(),
|
||||
None => vec!(),
|
||||
};
|
||||
println!("{:?}", raw_metadata);
|
||||
let item_type = matches.value_of("TYPE").unwrap();
|
||||
let title = matches.value_of("TITLE").unwrap();
|
||||
let mut metadata = HashMap::new();
|
||||
if &args[3] == "web" {
|
||||
if item_type == "web" {
|
||||
metadata.insert(
|
||||
"mediatype".to_string(),
|
||||
"web".to_string()
|
||||
);
|
||||
}
|
||||
else if &args[3] == "text" {
|
||||
else if item_type == "text" {
|
||||
metadata.insert(
|
||||
"mediatype".to_string(),
|
||||
"
|
||||
"texts".to_string(),
|
||||
);
|
||||
}
|
||||
else if item_type == "wiki" {
|
||||
metadata.insert(
|
||||
"mediatype".to_string(),
|
||||
"texts".to_string(),
|
||||
);
|
||||
metadata.insert(
|
||||
"subject".to_string(),
|
||||
"MediaWiki; wiki; wikiteam".to_string(),
|
||||
);
|
||||
}
|
||||
else if item_type == "none" {
|
||||
}
|
||||
else {
|
||||
unimplemented!("Unsupported item type. Currently supported; web texts wiki none");
|
||||
}
|
||||
metadata.insert(
|
||||
"title".to_string(),
|
||||
title.to_string(),
|
||||
);
|
||||
for meta in raw_metadata {
|
||||
let meta_: Vec<&str> = meta.split(":").collect();
|
||||
if metadata.contains_key(meta_[0]) {
|
||||
metadata.remove(meta_[0]);
|
||||
}
|
||||
metadata.insert(
|
||||
meta_[0].to_string(),
|
||||
meta_[1].to_string()
|
||||
);
|
||||
}
|
||||
|
||||
// Setup variables for printing
|
||||
let tool = "ia upload";
|
||||
let mut options_metadata = "".to_string();
|
||||
let mut extra_options = "".to_string();
|
||||
for option in raw_options {
|
||||
extra_options = format!("{} {}", extra_options, option);
|
||||
}
|
||||
for (key, value) in &metadata {
|
||||
options_metadata = format!("{} --metadata \"{}:{}\"", options_metadata, key, value);
|
||||
}
|
||||
println!("{} {} {}", tool, options_metadata, extra_options);
|
||||
|
||||
println!("{}", identifier);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue