Initial rust project structure with clap
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-09-19 15:33:34 -04:00
parent 26a7ab742e
commit 1723c26ba9
7 changed files with 93 additions and 19 deletions

34
.gitignore vendored
View File

@ -1,23 +1,21 @@
# ---> Go # ---> Rust
# If you prefer the allow list template instead of the deny list, see community template: # Generated by Cargo
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore # will have compiled files and executables
# debug/
# Binaries for programs and plugins target/
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c` # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
*.test # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# Output of the go coverage tool, specifically when used with LiteIDE # These are backup files generated by rustfmt
*.out **/*.rs.bk
# Dependency directories (remove the comment below to include it) # MSVC Windows builds of rustc generate these, which store debugging information
# vendor/ *.pdb
# Go workspace file
go.work
# Added by cargo
/target

30
.woodpecker.yml Normal file
View File

@ -0,0 +1,30 @@
pipeline:
tests:
image: rust:1.63
commands:
- "cargo test"
build_release:
image: rust:1.63
commands:
- "cargo install cargo-deb cargo-generate-rpm"
- "cargo build --release"
- "cargo deb"
- "cargo generate-rpm"
- "mv target/release/mcst target/release/mcst-${CI_COMMIT_TAG}-linux-x86_64"
when:
event: tag
gitea_release:
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_api_key
base_url: https://git.metaunix.net
files:
- "target/release/*${CI_COMMIT_TAG}-linux-x86_64"
- "target/debian/mcst*.deb"
- "target/generate-rpm/mcst*.rpm"
title: "${CI_COMMIT_TAG}"
when:
event: tag

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "mcst"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "3.2", features = ["derive"] }

View File

@ -1,4 +1,4 @@
Copyright (c) <year> <owner> Copyright (c) 2022 Bit Goblin
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1
src/cmd/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod new;

3
src/cmd/new.rs Normal file
View File

@ -0,0 +1,3 @@
pub fn new_command(server_name: &str, minecraft_version: &str) {
println!("Creating new server with name '{}' using version '{}'.", server_name, minecraft_version);
}

33
src/main.rs Normal file
View File

@ -0,0 +1,33 @@
mod cmd;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[clap(name = "Minecraft server management tool", author, version, about = "Bit Goblin's Minecraft server management tool.", long_about = None)]
#[clap(propagate_version = true)]
struct Cli {
#[clap(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
// new server subcommand
#[clap(name = "new", about = "Create a new Minecraft java edition server instance.")]
New {
#[clap(short = 'n', long, required = true, help = "[REQUIRED] The name for your new server")]
server_name: String,
#[clap(short = 'm', long, required = true, help = "[REQUIRED] Minecraft Java Edition server version to use.")]
minecraft_version: String,
},
}
fn main() {
// start the Clap CLI
let cli = Cli::parse();
// map subcommands back to the main command
match &cli.command {
Commands::New { server_name, minecraft_version } => cmd::new::new_command(&server_name, &minecraft_version),
}
}