Skip to content

Commit

Permalink
Show --help menu when tool run by itself (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
ismet55555 authored Aug 13, 2023
1 parent a458e88 commit d596beb
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 96 deletions.
91 changes: 0 additions & 91 deletions .github/workflows/release_github.yml

This file was deleted.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ bieye v0.0.0
This CLI tool reads text and returns it back in bionic reading format
for blazingly fast loading and even faster reading!
Example Usages:
bieye "Keep on reading"
echo "Read faster, learn more" | bieye --dim
man vim | bieye --dim --color
Usage: bieye [OPTIONS] [TEXT]
Arguments:
Expand Down
99 changes: 99 additions & 0 deletions dev/dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,102 @@ pub fn main() -> Result<()> {
required = false,
)]
pub color_name: Option<String>,





//////////////////////////////////////////////////////////////////////////////////
/// GitHub Actions Release Workflow
//////////////////////////////////////////////////////////////////////////////////
---
name: Release to GitHub

on:
push:
tags:
- v1.*

jobs:
create-release:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
needs: Testing # Test GitHub Workflow

strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
name: Linux Binary 64-Bit
target: x86_64-unknown-linux-musl

- os: macos-latest
name: MacOS Binary 64-Bit
target: x86_64-apple-darwin
target2: aarch64-apple-darwin
env:
MACOSX_DEPLOYMENT_TARGET: 10.7

- os: windows-latest
name: Windows Binary 64-Bit
target: x86_64-pc-windows-msvc

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Add rustup default target
run: rustup target add ${{ matrix.target }}

- name: Add rustup Apple ARM64 target
if: ${{ matrix.os == 'macos-latest' }}
run: rustup target add ${{ matrix.target2 }}

- name: Build default target in release mode
run: cargo build --release --target ${{ matrix.target }} --locked

- name: Build Apple ARM64 target in release mode
if: ${{ matrix.os == 'macos-latest' }}
run: cargo build --release --target ${{ matrix.target2 }} --locked

- name: Get latest release version number
id: get_version
uses: battila7/get-version-action@v2

- name: Create zip file on Windows
if: ${{ matrix.os == 'windows-latest' }}
run: |
choco install zip
cd target/${{ matrix.target }}/release
zip bieye-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.zip bieye.exe
cd ../../..

- name: Create tar.gz file on macOS
if: ${{ matrix.os == 'macos-latest' }}
run: |
chmod +x target/${{ matrix.target }}/release/bieye
tar -zcf target/${{ matrix.target }}/release/bieye-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release bieye
chmod +x target/${{ matrix.target2 }}/release/bieye
tar -zcf target/${{ matrix.target2 }}/release/bieye-${{ steps.get_version.outputs.version }}-${{ matrix.target2 }}.tar.gz -C target/${{ matrix.target2 }}/release bieye

- name: Create tar.gz file on Linux
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
chmod +x target/${{ matrix.target }}/release/bieye
tar -zcf target/${{ matrix.target }}/release/bieye-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release bieye

- name: Upload release and assets to GitHub
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }}
release_name: bieye ${{ steps.get_version.outputs.version }}
file_glob: true
file: target/*/release/bieye-${{ steps.get_version.outputs.version }}-*.{zip,tar.gz}

- name: Upload release to crates.io
uses: katyo/publish-crates@v2
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
6 changes: 5 additions & 1 deletion src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const DESCRIPTION: &str = concat!(
env!("CARGO_PKG_VERSION"),
"\n\n",
"This CLI tool reads text and returns it back in bionic reading format\n",
"for blazingly fast loading and even faster reading!",
"for blazingly fast loading and even faster reading!\n\n",
"Example Usages:\n",
" bieye \"Keep on reading\"\n",
" echo \"Read faster, learn more\" | bieye --dim\n",
" man vim | bieye --dim --color",
);

#[derive(Parser, Debug)]
Expand Down
16 changes: 12 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use color_eyre::eyre::Result;
use log::debug;
use std::io::{self, Read};
use std::io::{self, stdin, IsTerminal, Read};

pub mod bieye;
mod cli_args;

use bieye::Bieye;
use clap::CommandFactory;
use clap::Parser;
use cli_args::CliArgs;

#[cfg(not(target_family = "wasm"))]
fn main() -> Result<()> {
color_eyre::install()?;
env_logger::init();
Expand All @@ -22,12 +24,18 @@ fn main() -> Result<()> {
// Load user input text
if let Some(text) = _args.text {
// Passed via command line option flag
debug!("Reading input from command line argument ...");
input_text = text;
} else {
// Passed via stdin pipe
io::stdin().read_to_string(&mut input_text)?;
if input_text.is_empty() {
println!("ERROR: No input received via stdin.");
debug!("Reading input from stdin ...");
let is_stdin_available = !stdin().is_terminal();
if is_stdin_available {
io::stdin().read_to_string(&mut input_text)?;
} else {
debug!("No input received via stdin.");
let mut cmd = CliArgs::command();
cmd.print_help()?;
return Ok(());
}
}
Expand Down

0 comments on commit d596beb

Please sign in to comment.