Skip to content

Commit

Permalink
feat: embed version from git
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeladler committed Sep 1, 2024
1 parent dfa1280 commit c0e41ba
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Install deps
run: sudo apt-get update -q && sudo apt-get install -y libnotmuch-dev
- name: Generate files
run: cargo build
run: cargo run --bin notmuch-mailmover-generate
env:
GEN_ARTIFACTS: share
- name: Check if files have changed
Expand Down
23 changes: 22 additions & 1 deletion Cargo.lock

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

32 changes: 21 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
[package]
name = "notmuch-mailmover"
version = "0.2.0"
version = "0.0.0"
authors = ["Michael Adler <[email protected]>"]
description = "Move notmuch tagged mails into Maildir folders"
homepage = "https://github.com/michaeladler/notmuch-mailmover"
license = "Apache-2.0"
edition = "2021"

[lib]
name = "nm_mailmover"
path = "src/lib/mod.rs"

[[bin]]
name = "notmuch-mailmover"
path = "src/main.rs"

[[bin]]
name = "notmuch-mailmover-generate"
path = "src/generate.rs"

[profile.release]
lto = true
panic = "abort"
codegen-units = 1

[dependencies]
uuid = { version = "1.10.0", features = ["v4"] }
anyhow = "1.0.82"
Expand All @@ -18,16 +35,9 @@ serde_yaml = "0.9.34"
directories = "5.0.1"
shellexpand = "3.0.0"
clap = { version = "4.5.13", features = [ "derive", "cargo" ] }

[dev-dependencies]
regex = "1.10.6"

[build-dependencies]
clap = { version = "4.5.13", features = [ "derive", "cargo" ] }
clap_complete = "4.5.13"
clap_mangen = "0.2.23"
git-version = "0.3.9"

[profile.release]
lto = true
panic = "abort"
codegen-units = 1
[dev-dependencies]
regex = "1.10.6"
29 changes: 0 additions & 29 deletions build.rs

This file was deleted.

26 changes: 26 additions & 0 deletions src/generate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::env;
use std::ffi::OsString;
use std::fs::{create_dir_all, File};
use std::path::Path;
use std::str::FromStr;

use clap::{CommandFactory, ValueEnum};
use clap_complete::{generate_to, Shell};
use clap_mangen::Man;

use nm_mailmover::cli::Cli;

fn main() {
let dir = env::var_os("GEN_ARTIFACTS").unwrap_or(OsString::from_str(".").unwrap());
let out = Path::new(&dir);
create_dir_all(out).unwrap();
let cmd = &mut Cli::command();

Man::new(cmd.clone())
.render(&mut File::create(out.join("notmuch-mailmover.1")).unwrap())
.unwrap();

for shell in Shell::value_variants() {
generate_to(*shell, cmd, "notmuch-mailmover", out).unwrap();
}
}
File renamed without changes.
14 changes: 12 additions & 2 deletions src/cli.rs → src/lib/cli.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
use std::path::PathBuf;

use clap::{crate_authors, crate_version, Parser, ValueEnum};
use clap::{crate_authors, Parser, ValueEnum};

use git_version::git_version;

pub const VERSION: &str = git_version!(
cargo_prefix = "",
prefix = "",
// Note that on the CLI, the v* needs to be in single quotes
// When passed here though there seems to be some magic quoting that happens.
args = ["--always", "--dirty=-dirty", "--match=v*", "--tags"]
);

#[derive(Parser)]
#[clap(
name = "notmuch-mailmover",
version = crate_version!(),
version = VERSION,
author = crate_authors!(),
)]
pub struct Cli {
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/lib/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod action;
pub mod cli;
pub mod config;
pub mod engine;
pub mod repo;
File renamed without changes.
13 changes: 4 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
mod action;
mod cli;
mod config;
mod engine;
mod repo;

use clap::Parser;
use std::time::Instant;

use anyhow::Result;
use clap::Parser;
use env_logger::Env;
use log::{debug, info};
use std::time::Instant;

use nm_mailmover::{action, cli, config, engine};

fn main() -> Result<()> {
let opts = cli::Cli::parse();
Expand Down

0 comments on commit c0e41ba

Please sign in to comment.