Skip to content

Commit

Permalink
doc: Add hello example
Browse files Browse the repository at this point in the history
  • Loading branch information
juanibiapina committed May 27, 2024
1 parent 005ed59 commit f881f80
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ Then add it to your packages:

This section explains how to set up a CLI called `hat` using `sub`.

### Hello World

For a working example, check out a [hello
world])(https://github.com/juanibiapina/sub/tree/master/examples/hello) project.

### As an alias

The quickest way to get started with `sub` is to define an alias for your CLI
Expand Down
23 changes: 23 additions & 0 deletions examples/hello/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Hello project

This is an example project on how you can structure your CLI called `hello`
with a subcommand `world`.

To run it from this repo's root, make sure `sub` is installed and run:

```sh
./examples/hello/bin/hello
```

And to actually print "Hello, world!" run:

```sh
./examples/hello/bin/hello world
```

If you want to use this project as a template, simply replace the two
occurrences of `hello` with your CLI name (for example `hat`):

1. The file `bin/hello` should be renamed to `bin/hat`.
2. The argument `--name hello` in `bin/hello` (now `bin/hat`) should be changed
to `--name hat`.
5 changes: 5 additions & 0 deletions examples/hello/bin/hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#/usr/bin/env bash

set -e

sub --name hello --executable "${BASH_SOURCE[0]}" --relative ".." -- "$@"
13 changes: 13 additions & 0 deletions examples/hello/libexec/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Summary: CLI implementation of Hello World
#
# A "Hello, World!" program is generally a simple computer program which outputs
# (or displays) to the screen (often the console) a message similar to "Hello,
# World!" while ignoring any user input. A small piece of code in most
# general-purpose programming languages, this program is used to illustrate a
# language's basic syntax. A "Hello, World!" program is often the first written
# by a student of a new programming language,[1] but such a program can also be
# used as a sanity check to ensure that the computer software intended to compile
# or run source code is correctly installed, and that its operator understands
# how to use it.
#
# https://en.wikipedia.org/wiki/%22Hello,_World!%22_program
7 changes: 7 additions & 0 deletions examples/hello/libexec/world
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Summary: Say hello
# Usage: {cmd}

set -e

echo "Hello, world!"

0 comments on commit f881f80

Please sign in to comment.