-
Notifications
You must be signed in to change notification settings - Fork 0
Home
What is TARS ?
How to use TARS in your command-line projects ?
How to customize message-of-the-day (MOTD) and the prompt ?
How to extend TARS by adding new commands ?
How to use colors in outputs ?
TARS is a framework, which provides a command-line interface to interact with users of your applications like CLI clients e.g mongo, mysql, etc. TARS provides a baseline functionality of a command-line application. It even understands a few commands like "help" and "quit". You only need to extend it to make TARS understand your custom commands according to your use cases.
To add the CLI into your application just add the dependency and the define the main function.
(defproject your-app "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]
[io.ryos/tars "0.1.4"]]
:main io.moo.tars.container)
After you run your application by calling:
lein run
the CLI will be available for user interaction with a default MOTD and prompt. You can override this settings and customize them in your applications.
.
_|_
/\/\ (. .)
`||' |#|
||__.-"-"-.___
`---| . . |--.\ TARS version 0.1.0 [ Type 'help' to get help! ]
| : : | |_| https://github.com/ryos-io/tars
`..-..' ( I )
|| || | |
|| || |_|
|__|__| (.)
tars>
Out of the box, TARS provide two commands, that are "help" and "quit". You can now extend the TARS to understand your commands.
You can override the MOTD by creating a new branding file under "/.tars/branding" and also the prompt by adding a configuration file in "/.tars/config.clj". The configuration file will be loaded while the CLI starts. To override the prompt settings, just add a new definition for the prompt:
(def config {:prompt "tars"})
To add your own commands you can use the TARS DSL:
(ns test-prj.core
(:gen-class)
(:require [io.ryos.tars.container :as c])
(:use io.ryos.tars.dsl))
;; add a new command called "test"
(add-command "test"
(on-start (println "starting"))
(on-exec (println "exec"))
(on-complete (println "complete"))
(on-error (println "error"))
(with-doc "Command Description"))
(defn -main [ & args ]
(c/start-repl))
There are some color codes defined in io.ryos.tars.colors
namespace.
To use them, just wrap the color-code and reset-color symbol around your text:
(r/prints print _B "Hello world!" _R_)
This writes a blue "Hello world" out and then after it resets the color mode.