Use clap to extract package version from cargo

ida_star
Wilfred Hughes 2021-08-27 22:34:51 +07:00
parent 1d0b1ad6b6
commit 72640815b1
1 changed files with 2 additions and 4 deletions

@ -11,7 +11,7 @@ mod style;
mod syntax; mod syntax;
mod tree_sitter_parser; mod tree_sitter_parser;
use atty::Stream; use atty::Stream;
use clap::{App, AppSettings, Arg}; use clap::{crate_version, App, AppSettings, Arg};
use std::env; use std::env;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::path::Path; use std::path::Path;
@ -23,8 +23,6 @@ use crate::lines::{join_overlapping, visible_groups, MaxLine};
use crate::syntax::{change_positions, init_info, matching_lines}; use crate::syntax::{change_positions, init_info, matching_lines};
use crate::tree_sitter_parser as tsp; use crate::tree_sitter_parser as tsp;
const VERSION: &str = env!("CARGO_PKG_VERSION");
fn configure_color() { fn configure_color() {
if atty::is(Stream::Stdout) || env::var("GIT_PAGER_IN_USE").is_ok() { if atty::is(Stream::Stdout) || env::var("GIT_PAGER_IN_USE").is_ok() {
// Always enable colour if stdout is a TTY or if the git pager is active. // Always enable colour if stdout is a TTY or if the git pager is active.
@ -49,7 +47,7 @@ enum Mode {
fn parse_args() -> Mode { fn parse_args() -> Mode {
let matches = let matches =
App::new("Difftastic") App::new("Difftastic")
.version(VERSION) .version(crate_version!())
.about("A syntax aware diff.") .about("A syntax aware diff.")
.author("Wilfred Hughes") .author("Wilfred Hughes")
.arg(Arg::with_name("dump-syntax").long("dump-syntax").help( .arg(Arg::with_name("dump-syntax").long("dump-syntax").help(