Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ylxdzsw/fire.jl
Fire.jl is a library for automatically generating command line interfaces (CLIs) for julia functions.
https://github.com/ylxdzsw/fire.jl
cli julia macro-fu
Last synced: 24 days ago
JSON representation
Fire.jl is a library for automatically generating command line interfaces (CLIs) for julia functions.
- Host: GitHub
- URL: https://github.com/ylxdzsw/fire.jl
- Owner: ylxdzsw
- License: other
- Created: 2017-03-04T08:38:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-26T07:59:17.000Z (over 1 year ago)
- Last Synced: 2024-10-11T10:06:19.208Z (about 1 month ago)
- Topics: cli, julia, macro-fu
- Language: Julia
- Size: 23.4 KB
- Stars: 63
- Watchers: 4
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Fire.jl
=======[![](https://github.com/ylxdzsw/Fire.jl/workflows/CI/badge.svg)](https://github.com/ylxdzsw/Fire.jl/actions)
Fire.jl is a library for creating simple CLI from julia function definitions.
### Installation
```julia
import Pkg
Pkg.add("Fire")
```### Usage
1. put `using Fire` on the top
2. put `@main` in front of the entry function
3. (optional) add `#!/usr/bin/env julia` and `chmod +x````julia
using Fire"Very Descriptive Doc String"
@main function repeat_string(message::AbstractString, times::Integer=3; color::Symbol=:normal)
times < 0 && throw(ArgumentError("cannot repeat negative times"))
for i in 1:times
printstyled(message, '\n'; color)
end
end
```Then this function can be used at commandline (assuming the file is called "example.jl")
```
$ julia example.jl hello
hello
hello
hello$ julia example.jl 'hello world!' 1
hello world!$ julia example.jl 'hello world!' 1 --color red
hello world!$ julia example.jl --help
Very Descriptive Doc StringPositional Arguments:
str: AbstractString
times: Integer (default: 3)Optional Arguments:
color: Symbol (default: :normal)
```Multiple entries are supported.
```julia
using Fire@main function is_odd(x::Integer)
x == 0 ? println("false") : is_even(x-sign(x))
end@main function is_even(x::Integer)
x == 0 ? println("true") : is_odd(x-sign(x))
end
``````
$ julia example.jl is_odd 3
true$ julia example.jl is_even 3
false
```### Why is it called Fire?
This package is inspired by [python-fire](https://github.com/google/python-fire)
### Details
#### Supported Types
- String / AbstractString / Symbol
- "basic" number types like `Int32`, `AbstractFloat`, etc.
- VarArgs of above types
- Vector of above types is allowed in optional arguments
- Bool is allowed in optional arguments, and will be parsed as flag