Skip to content

Commit

Permalink
add util: dirname
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarzik committed Feb 26, 2024
1 parent 572f0b8 commit 5963240
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pathnames/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ gettext-rs = { version = "0.7", features = ["gettext-system"] }
name = "basename"
path = "src/basename.rs"

[[bin]]
name = "dirname"
path = "src/dirname.rs"

41 changes: 41 additions & 0 deletions pathnames/src/dirname.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright (c) 2024 Jeff Garzik
//
// This file is part of the posixutils-rs project covered under
// the MIT License. For the full license text, please see the LICENSE
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//

extern crate clap;
extern crate plib;

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, textdomain};
use plib::PROJECT_NAME;
use std::path::PathBuf;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about)]
struct Args {
pathname: String,
}

fn show_dirname(args: &Args) {
let mut pb = PathBuf::from(&args.pathname);
pb.pop();

println!("{}", pb.to_string_lossy());
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
// parse command line arguments
let args = Args::parse();

textdomain(PROJECT_NAME)?;
bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?;

show_dirname(&args);

Ok(())
}

0 comments on commit 5963240

Please sign in to comment.