Skip to content

Fire.jl is a library for automatically generating command line interfaces (CLIs) for julia functions.

License

Notifications You must be signed in to change notification settings

ylxdzsw/Fire.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fire.jl

Fire.jl is a library for creating simple CLI from julia function definitions.

Installation

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
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 String

Positional Arguments:
    str: AbstractString
    times: Integer (default: 3)

Optional Arguments:
    color: Symbol (default: :normal)

Multiple entries are supported.

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

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

About

Fire.jl is a library for automatically generating command line interfaces (CLIs) for julia functions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages