├── .gitignore ├── .travis.yml ├── LICENSE ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── hello.rkt ├── info.rkt ├── names.txt ├── scribblings └── cli-command.scrbl └── test.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | \#* 3 | .\#* 4 | .DS_Store 5 | compiled/ 6 | /doc/ 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | # Based on: https://github.com/greghendershott/travis-racket 4 | 5 | env: 6 | global: 7 | # Supply a global RACKET_DIR environment variable. This is where 8 | # Racket will be installed. A good idea is to use ~/racket because 9 | # that doesn't require sudo to install. 10 | - RACKET_DIR=~/racket 11 | matrix: 12 | # Supply at least one RACKET_VERSION environment variable. This is 13 | # used by the install-racket.sh script (run at before_install, 14 | # below) to select the version of Racket to download and install. 15 | # 16 | # Supply more than one RACKET_VERSION (as in the example below) to 17 | # create a Travis-CI build matrix to test against multiple Racket 18 | # versions. 19 | - RACKET_VERSION=8.8 20 | - RACKET_VERSION=HEAD 21 | 22 | matrix: 23 | allow_failures: 24 | # - env: RACKET_VERSION=HEAD 25 | fast_finish: true 26 | 27 | before_install: 28 | - git clone https://github.com/greghendershott/travis-racket.git ~/travis-racket 29 | - cat ~/travis-racket/install-racket.sh | bash # pipe to bash not sh! 30 | - export PATH="${RACKET_DIR}/bin:${PATH}" #install-racket.sh can't set for us 31 | 32 | install: 33 | - raco pkg install --auto --name cli-command 34 | 35 | before_script: 36 | 37 | # Here supply steps such as raco make, raco test, etc. You can run 38 | # `raco pkg install --deps search-auto` to install any required 39 | # packages without it getting stuck on a confirmation prompt. 40 | script: 41 | - raco test -x -p cli-command 42 | 43 | after_success: 44 | - raco setup --check-pkg-deps --pkgs cli-command 45 | - raco pkg install --auto cover cover-coveralls 46 | - raco cover -b -f coveralls -d $TRAVIS_BUILD_DIR/coverage . 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Racket Templates 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Copyright 2020 spdegabrielle 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | cli-command 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 spdegabrielle 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Racket](https://img.shields.io/badge/-Made%20with%20Racket-darkred?logo=racket)](https://racket-lang.org) 2 | [![Racket](https://img.shields.io/badge/-Made%20with%20Racket%20Templates-lightgrey?logo=racket)](https://github.com/racket-templates) 3 | [![Discourse users](https://img.shields.io/discourse/users?label=Discuss%20on%20Racket%20Discourse&logo=racket&server=https%3A%2F%2Fracket.discourse.group)](https://racket.discourse.group/t/racket-templates-project/156?u=spdegabrielle) 4 | [![Racket Discord](https://img.shields.io/discord/571040468092321801?label=Chat%20on%20Racket%20Discord&logo=racket)](https://discord.gg/6Zq8sH5) 5 | 6 | cli-command 7 | =========== 8 | 9 | A working example of CLI command you can use to create your own command line app. 10 | 11 | # How To Install 12 | 13 | 1. [Set your PATH environment variable](https://github.com/racket/racket/wiki/Set-your-PATH-environment-variable) 14 | so you can use `raco` and other Racket command line functions. 15 | 2. either look for `from-template` in the DrRacket menu **File|Package Manager**, or run the `raco` command: 16 | ```bash 17 | raco pkg install from-template 18 | ``` 19 | 3. 20 | ```bash 21 | raco new cli-command 22 | ``` 23 | If you omit ``, the command will add copy the template to a folder called `cli-command` in the current folder. 24 | 25 | # How to use 26 | 27 | This is working example that you can change to suit your needs. 28 | 29 | If you need to create an interactive app consider using the [`charterm`](https://docs.racket-lang.org/charterm/index.html) package. 30 | 31 | # How to create an executable 32 | 33 | `$ raco exe -o hello hello.rkt` 34 | 35 | This will create an executabe `hello` or `hello.exe` depending on your platform. 36 | 37 | For help 38 | 39 | `$ ./hello -h` or `hello.exe -h` 40 | 41 | 42 | Creating executables: https://docs.racket-lang.org/raco/exe.html 43 | 44 | Command-line parsing: https://docs.racket-lang.org/reference/Command-Line_Parsing.html 45 | 46 | ### Testing command-line parsing: 47 | 48 | Use the DrRacket `drracket-cmdline-args` plugin: https://docs.racket-lang.org/drracket-cmdline-args/ 49 | 50 | Install: `raco pkg install drracket-cmdline-args` 51 | 52 | ![drracket-cmdline-args](https://docs.racket-lang.org/drracket-cmdline-args/screenshot.png) 53 | 54 | -------------------------------------------------------------------------------- /hello.rkt: -------------------------------------------------------------------------------- 1 | #lang racket/base 2 | 3 | (module+ test 4 | (require rackunit)) 5 | 6 | ;; Notice 7 | ;; To create an executable 8 | ;; $ raco exe -o hello hello.rkt 9 | ;; 10 | ;; see https://docs.racket-lang.org/raco/exe.html 11 | ;; 12 | ;; To share stand-alone executables: 13 | ;; $ raco distribute executable ... 14 | ;; 15 | ;; e.g 16 | ;; $ raco distribute greetings hello.exe 17 | ;; 18 | ;; creates a directory "greetings" (if the directory doesn’t exist already), 19 | ;; and it copies the executables "hello.exe" and "goodbye.exe" into "greetings". 20 | ;; 21 | ;; see https://docs.racket-lang.org/raco/exe-dist.html 22 | ;; 23 | ;; For your convenience, we have included LICENSE-MIT and LICENSE-APACHE files. 24 | ;; If you would prefer to use a different license, replace those files with the 25 | ;; desired license. 26 | ;; 27 | ;; Some users like to add a `private/` directory, place auxiliary files there, 28 | ;; and require them in `main.rkt`. 29 | ;; 30 | ;; See the current version of the racket style guide here: 31 | ;; http://docs.racket-lang.org/style/index.html 32 | 33 | ;; Code here 34 | (require racket/cmdline racket/port) 35 | (define who (box "world")) 36 | (define (pipediput) 37 | (for ([line (port->lines)]) 38 | (printf "hello ~a~n" line))) 39 | (command-line 40 | #:program "Greeter" 41 | #:once-any 42 | [("-n" "--name") name "Who to say hello to" (set-box! who name)] 43 | [("-p" "--pipe") "greet piped list" (pipediput)] 44 | #:args () 45 | (printf "hello ~a~n" (unbox who))) 46 | 47 | 48 | (module+ test 49 | ;; Any code in this `test` submodule runs when this file is run using DrRacket 50 | ;; or with `raco test`. The code here does not run when this file is 51 | ;; required by another module. 52 | (check-equal? (unbox who) "world")) 53 | 54 | (module+ main 55 | ;; (Optional) main submodule. Put code here if you need it to be executed when 56 | ;; this file is run using DrRacket or the `racket` executable. The code here 57 | ;; does not run when this file is required by another module. Documentation: 58 | ;; http://docs.racket-lang.org/guide/Module_Syntax.html#%28part._main-and-test%29 59 | (define who (box "world"))) 60 | -------------------------------------------------------------------------------- /info.rkt: -------------------------------------------------------------------------------- 1 | #lang info 2 | (define collection "cli-command") 3 | (define deps '("base")) 4 | (define build-deps '("scribble-lib" "racket-doc" "rackunit-lib")) 5 | (define scribblings '(("scribblings/cli-command.scrbl" ()))) 6 | (define pkg-desc "Description Here") 7 | (define version "0.0") 8 | (define pkg-authors '(spdegabrielle)) 9 | -------------------------------------------------------------------------------- /names.txt: -------------------------------------------------------------------------------- 1 | Orlando 2 | Jack 3 | Sorawee 4 | Laurent 5 | Jens 6 | -------------------------------------------------------------------------------- /scribblings/cli-command.scrbl: -------------------------------------------------------------------------------- 1 | #lang scribble/manual 2 | @require[@for-label[cli-command 3 | racket/base]] 4 | 5 | @title{cli-command} 6 | @author{spdegabrielle} 7 | 8 | @defmodule[cli-command] 9 | 10 | Package Description Here 11 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | cat names.txt | ./hello -p 2 | ./hello -n Sam 3 | --------------------------------------------------------------------------------