Rust: Printing a short CLI usage message with clap

Clap can print a short usage message rather than the full help text. File: Cargo.toml [package] edition = "2021" # --snip-- [dependencies] clap = { version = "4.4.0", features = ["derive"] } File: src/ use clap::CommandFactory; use clap::Parser; #[derive(Parser)] struct Cli { /// First arg arg1: String, /// Second arg arg2: Vec<String>, } fn main() { let mut cmd = Cli::command(); println!("{}", cmd.render_usage()); } Result al@linux ~ $ ./clap_test Usage: clap_test <ARG1> [ARG2]....

August 28, 2023

Git: Fixing GPG signing errors

I use GPG to sign Git tags. This is a list of signing errors I encountered and possible solutions. # Error: $ git tag --sign --message 'Release 2023.07.13' 2023.07.13 # --snip-- gpg: signing failed: No pinentry error: unable to sign the tag # Problem: # This can happen in a container if GPG cannot find a tool to ask the user for a passphrase. # # Solution: dnf install pinentry # Error: $ git tag --sign --message 'Release 2023....

July 18, 2023

Git: Signing an already pushed commit

Given you have created a pull request (PR) with a single commit on GitHub. The commit is not GPG-signed. The maintainer asks you to sign the commit. If you are the only one working (committing) to this PR, you can force-push a signed commit. # Sign the latest commit on your local repository git commit --amend --no-edit --gpg-sign # Force push the commit to your remote repository (fork) git push --force-with-lease GitHub will automatically update your PR....

April 9, 2022

Git: Renaming tags

Be careful. Renaming tags might be difficult depending on your situation. There is no single step for renaming a tag. You must create a new tag with a new name and then delete the old tag. What you should know TLDR: When replacing tags, make sure that your new tag points to a commit object and not to an old tag object. Git has the following types of tags:...

December 12, 2021

Git: Deleting remote tags

Removing a remote tag: $ git push --delete <remote> <tag> $ git push --delete origin v1.0 Removing multiple remote tags: $ git push --delete <remote> <tag-1> <tag-2> <...> $ git push --delete origin v1.0

December 5, 2021

Python: Converting `datetime` and `string` types

Converting from datetime to string Use the datetime.strftime() method to convert a Python datetime object to a string of any format. >>> from datetime import datetime >>> dt = datetime(2009, 10, 1, 20, 36, 41) >>> dt.strftime('%d.%m.%Y %H:%M:%S') '01.10.2009 20:36:41' The argument to datetime.strftime() is a format string build with format codes. See strftime() and strptime() Format Codes for a list of available format codes. Converting from string to datetime Use the datetime....

February 16, 2021