1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-04-19 11:46:50 +00:00

Package deb package containing bash completion

This commit is contained in:
Paul-Christian Volkmer 2023-09-04 17:46:55 +02:00
parent e27d31a8bf
commit b3054f971e
6 changed files with 79 additions and 10 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.idea/* .idea/*
/target /target
/completion
*.iml *.iml

10
Cargo.lock generated
View File

@ -99,6 +99,15 @@ dependencies = [
"clap_lex", "clap_lex",
] ]
[[package]]
name = "clap_complete"
version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "586a385f7ef2f8b4d86bddaa0c094794e7ccbfe5ffef1f434fe928143fc783a5"
dependencies = [
"clap",
]
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.4.2" version = "4.4.2"
@ -262,6 +271,7 @@ name = "osc-variant"
version = "0.4.0" version = "0.4.0"
dependencies = [ dependencies = [
"clap", "clap",
"clap_complete",
"console", "console",
"quick-xml", "quick-xml",
"serde", "serde",

View File

@ -7,6 +7,8 @@ description = "Anwendung zum Anpassen einer OSC-Datei an einen Standort"
license = "MIT" license = "MIT"
readme = "README.md" readme = "README.md"
build = "build.rs"
[dependencies] [dependencies]
clap = { version = "4.4", features = ["std", "help", "usage", "derive", "error-context"], default-features = false } clap = { version = "4.4", features = ["std", "help", "usage", "derive", "error-context"], default-features = false }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
@ -15,6 +17,10 @@ quick-xml = { version = "0.30", features = ["escape-html", "serialize"], default
console = "0.15" console = "0.15"
sha256 = "1.4" sha256 = "1.4"
[build-dependencies]
clap = { version = "4.4", features = ["std", "help", "usage", "derive", "error-context"], default-features = false }
clap_complete = "4.4"
[profile.release] [profile.release]
opt-level = "s" opt-level = "s"
codegen-units = 1 codegen-units = 1
@ -24,3 +30,6 @@ panic = "abort"
[package.metadata.deb] [package.metadata.deb]
copyright = "Copyright (c) 2023 Comprehensive Cancer Center Mainfranken" copyright = "Copyright (c) 2023 Comprehensive Cancer Center Mainfranken"
assets = [
["completion/osc-variant.bash", "etc/bash_completion.d/", "644"]
]

44
build.rs Normal file
View File

@ -0,0 +1,44 @@
/*
* MIT License
*
* Copyright (c) 2023 Comprehensive Cancer Center Mainfranken
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
use std::fs;
use std::io::Error;
use clap_complete::generate_to;
use clap_complete::Shell::Bash;
include!("src/cli.rs");
fn main() -> Result<(), Error> {
let mut cmd = build_cli();
let package_name = std::env::var("CARGO_CRATE_NAME").unwrap_or("osc-variant".to_string());
fs::remove_dir_all("completion")?;
fs::create_dir("completion")?;
generate_to(Bash, &mut cmd, package_name.as_str(), "completion")?;
Ok(())
}

View File

@ -22,18 +22,23 @@
* SOFTWARE. * SOFTWARE.
*/ */
use clap::{Parser, Subcommand}; use clap::{Command, CommandFactory, Parser, Subcommand};
#[allow(dead_code)]
fn build_cli() -> Command {
Cli::command()
}
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
#[command(propagate_version = true, arg_required_else_help(true))] #[command(propagate_version = true, arg_required_else_help(true))]
pub struct Cli { pub struct Cli {
#[command(subcommand)] #[command(subcommand)]
pub command: Command, pub cmd: SubCommand,
} }
#[derive(Subcommand)] #[derive(Subcommand)]
pub enum Command { pub enum SubCommand {
#[command( #[command(
name = "sha256sum", name = "sha256sum",
about = "Berechne SHA256 Prüfsumme für die angegebene Datei" about = "Berechne SHA256 Prüfsumme für die angegebene Datei"

View File

@ -37,7 +37,7 @@ use quick_xml::se::Serializer;
use serde::Serialize; use serde::Serialize;
use sha256::digest; use sha256::digest;
use crate::cli::{Cli, Command}; use crate::cli::{Cli, SubCommand};
use crate::model::onkostar_editor::OnkostarEditor; use crate::model::onkostar_editor::OnkostarEditor;
use crate::profile::Profile; use crate::profile::Profile;
@ -111,8 +111,8 @@ fn read_profile(filename: String) -> Result<Profile, FileError> {
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let cli = Cli::parse(); let cli = Cli::parse();
match cli.command { match cli.cmd {
Command::List { SubCommand::List {
inputfile, inputfile,
sorted, sorted,
filter, filter,
@ -127,7 +127,7 @@ fn main() -> Result<(), Box<dyn Error>> {
} }
data.print_list(); data.print_list();
} }
Command::Tree { SubCommand::Tree {
inputfile, inputfile,
sorted, sorted,
filter, filter,
@ -142,7 +142,7 @@ fn main() -> Result<(), Box<dyn Error>> {
} }
OnkostarEditor::print_tree(&data); OnkostarEditor::print_tree(&data);
} }
Command::Modify { SubCommand::Modify {
inputfile, inputfile,
profile, profile,
outputfile, outputfile,
@ -193,7 +193,7 @@ fn main() -> Result<(), Box<dyn Error>> {
} }
} }
} }
Command::Diff { SubCommand::Diff {
inputfile_a, inputfile_a,
inputfile_b, inputfile_b,
strict, strict,
@ -209,7 +209,7 @@ fn main() -> Result<(), Box<dyn Error>> {
data_a.print_diff(data_b, strict); data_a.print_diff(data_b, strict);
} }
Command::Sha256Sum { inputfile } => { SubCommand::Sha256Sum { inputfile } => {
match fs::read_to_string(inputfile.clone()) { match fs::read_to_string(inputfile.clone()) {
Ok(content) => { Ok(content) => {
println!( println!(