项目作者: v-i-s-h

项目描述 :
Provides `@runit` macro for running scripts with commandline arguments from REPL
高级语言: Julia
项目地址: git://github.com/v-i-s-h/Runner.jl.git
创建时间: 2020-08-06T15:44:24Z
项目社区:https://github.com/v-i-s-h/Runner.jl

开源协议:MIT License

下载


Runner.jl

deps
version
pkgeval

TL;DR Provides @runit macro for running scripts with commandline arguments from REPL.

Instead of

  1. $julia script.jl arg1 arg2 arg3

use, from REPL

  1. julia> @runit "script.jl arg1 arg2 arg3"

Advantage: Avoid the delay in package load times during development. Load it once using REPL and continue using it with commandline arguments.

Why?

This packages tries to solve the problem of running scripts with commandline arguments from REPL. Often we write scripts that can be called from commandline with arguments like

  1. $julia script.jl arg1 arg2 arg3

However, during development, this may become cumbersome. If we use some packages which has long load times, running the script as above will create long delays before actually executing the code. A faster approach during development is to start a REPL and use

  1. julia> include('script.jl')

But, in this case, we will not be able to provide command line arguments. Work around is to define a function which takes in arguments and manually calling it. Not neat!

This package exists to overcome this difficulty. It provide a macro @runit which will let you run script from REPL with commandline arguments.

How?

Simple use case

If you have a script like

  1. # hello.jl
  2. # Simple script for demo. Accesses ARGS
  3. println("Hello $(ARGS[1])!")

From commadline, we can run this as

  1. $julia hello.jl Julia

To run this from REPL, use

  1. julia> @runit hello.jl Julia

Use with ArgParse

  1. # Script hello2.jl
  2. using ArgParse
  3. parser = ArgParseSettings()
  4. @add_arg_table! parser begin
  5. "name"
  6. help = "Name to greet"
  7. arg_type = String
  8. "--greet"
  9. help = "Greeting sting"
  10. arg_type = String
  11. default = "Hello"
  12. end
  13. parsed_args = parse_args(parser)
  14. println(parsed_args["greet"], " ", parsed_args["name"], "!")

From commandline

  1. $julia hello2.jl Julia
  2. Hello Julia!
  3. $julia hello2.jl Julia --greet Namaste
  4. Namaste Julia!

From REPL

  1. julia> @runit "hello2.jl Julia"
  2. Hello Julia!
  3. julia> @runit "hello2.jl Julia --greet Namaste"
  4. Namaste Julia!