Skip to content

Commit

Permalink
Improve version and help text
Browse files Browse the repository at this point in the history
Added copyright information and links to both the version and help text,
as well as just generally improving the formatting of the help text.
  • Loading branch information
rushsteve1 committed Aug 14, 2021
1 parent 448fb08 commit b8aa5b1
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions trash.d
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import std.random;
import std.format;
import std.datetime.systime : Clock, SysTime;
import std.string;
import std.outbuffer : OutBuffer;
import core.memory;
import core.stdc.errno : ENOENT, EXDEV;

Expand All @@ -53,7 +54,17 @@ import core.stdc.errno : ENOENT, EXDEV;
*/

/// trash-d is versioned sequentially starting at 1
const int VER = 6;
const int VER = 7;
const string VER_NAME = "Providence";
const string VER_TEXT = format("trash-d version %s '%s'", VER, VER_NAME);
const string COPY_TEXT = "Copyright (C) 2021 Steven vanZyl.
License MIT <https://mit-license.org/>.
Fork on GitHub <https://github.com/rushsteve1/trash-d>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Steven vanZyl <rushsteve1@rushsteve1.us>.";

/**
The parsed command line options are stored in this struct
Expand Down Expand Up @@ -155,12 +166,6 @@ struct TrashFile {
deletion_date = now;
}

// A `TrashFile` MUST always have a `file_name` and an `orig_path`
invariant {
assert(file_name);
assert(orig_path);
}

/// Path to the file in the trash bin
@property string file_path() const {
return OPTS.files_dir ~ "/" ~ file_name;
Expand Down Expand Up @@ -489,18 +494,18 @@ int parseOpts(ref string[] args) {
// Pass through flags that weren't understood
// These will get ignored later, but it adds graceful rm compatibility
std.getopt.config.passThrough,
"dir|d", "Remove empty directories", &OPTS.dir,
"recursive|r", "Delete directories and their contents", &OPTS.recursive,
"verbose|v", "Print more information", &OPTS.verbose,
"interactive|i", "Ask before each deletion", &OPTS.interactive,
"force|f", "Ignore non-existant and don't prompt", &OPTS.force,
"version", "Output the version and exit", &OPTS.ver,

"empty", "Empty the trash bin", &OPTS.empty,
"delete", "Delete a file from the trash", &OPTS.del,
"list", "List out the files in the trash", &OPTS.list,
"restore", "Restore a file from the trash", &OPTS.restore,
"rm", "Escape hatch to permanently delete a file", &OPTS.rm,
"dir|d", "Remove empty directories.", &OPTS.dir,
"recursive|r", "Delete directories and their contents.", &OPTS.recursive,
"verbose|v", "Print more information.", &OPTS.verbose,
"interactive|i", "Ask before each deletion.", &OPTS.interactive,
"force|f", "Ignore non-existant and don't prompt.", &OPTS.force,
"version", "Output the version and exit.", &OPTS.ver,

"empty", "Empty the trash bin.", &OPTS.empty,
"delete", "Delete a file from the trash.", &OPTS.del,
"list", "List out the files in the trash.", &OPTS.list,
"restore", "Restore a file from the trash.", &OPTS.restore,
"rm", "Escape hatch to permanently delete a file.", &OPTS.rm,
);
// dfmt on
} catch (GetOptException e) {
Expand All @@ -510,8 +515,11 @@ int parseOpts(ref string[] args) {
// Handle requests for help text
// This includes when no arguments are given
if (helpInfo.helpWanted || arglen < 2) {
defaultGetoptPrinter("trash [OPTION]... [FILE]...\nA near drop-in replacement for rm that uses the trash bin",
helpInfo.options);
string text = "Usage: \033[1mtrash [OPTIONS...] [FILES...]\033[0m\n";
OutBuffer buf = new OutBuffer();
defaultGetoptFormatter(buf, text, helpInfo.options, "\t%*s %*s\t%*s%s\x0a");
writefln("%s\n\n%s\n%s", VER_TEXT, buf, COPY_TEXT);

if (arglen < 2)
return 1;
return -1;
Expand All @@ -520,13 +528,7 @@ int parseOpts(ref string[] args) {
// Print the version number and return
// This is here so that the program quits out on --version quickly
if (OPTS.ver) {
writefln("trash-d version %s
Copyright (C) 2021 Steven vanZyl.
Fork on GitHub <https://github.com/rushsteve1/trash-d>
License MIT <https://mit-license.org/>.
There is NO WARRANTY, to the extent permitted by law.
Written by Steven vanZyl <rushsteve1@rushsteve1.us>.", VER);
writefln("\033[1m%s\033[0m\n\n%s", VER_TEXT, COPY_TEXT);
return -1;
}

Expand Down

0 comments on commit b8aa5b1

Please sign in to comment.