Giter Club home page Giter Club logo

runfile's Introduction

Runfile - command line for your projects

Gem Version Build Status Maintainability


A beautiful command line utility builder
Rake-inspired โœฆ Docopt inside
runfile.dannyb.co


Runfile lets you create command line tools in a way similar to Rake, but with the full power of Docopt command line options.

You create a runfile, and execute commands with run command arguments -and --flags.

Runfile is designed primarily for Ruby developers, but if you need to add a command line "toolbelt" for your projects, you can use it regardless.

Demo

Runfile Demo

Install

$ gem install runfile --pre

Quick Start

$ run new        # create a new runfile
$ run --help     # show the usage patterns
$ vi runfile     # edit the runfile

Example

A simple runfile looks like this. You can get this template by running run new (in a directory without other runfiles).

title   'Greeter'
summary 'A sample runfile'

usage  'hello [NAME --shout]'
help   'Say hello'
option '--shout, -s', 'Greet louder'
action 'hello' do |args|
  name = args['NAME'] || 'You...'
  message = "Hello #{name}"
  message = "#{message.upcase}!" if args['--shout']

  say "gu`#{message}`"
end

You can then run it by executing this command:

$ run hello Luke
Hello Luke

It will behave in the same way you expect any standard command line interface to behave,

# Show usage summary
$ run
Usage:
  run hello [NAME --shout]
  run (--help | -h)

# Show detailed help
$ run --help
Greeter

  A sample runfile

Usage:
  run hello [NAME --shout]
  run (--help | -h)

Commands:
  hello
    Say hello

Options:
  --shout, -s
    Greet louder

  --help, -h
    Show this message

More Examples

You can learn almost everything there is to know about runfile from the examples.

You can get any of these examples directly in your terminal by running:

$ run example --help

Documentation

For a more formal documentation, see the User Guide.

Breaking Changes in 1.0.0

Show section

If you are using a version earlier than 1.0, note that version 1.0.0 includes some breaking changes. You can read more about them in this Pull Request.

Upgrading to 1.0.0

No more .runfile config

If you have used the multi-runfile config file, this no longer exists. Use a standard runfile instead, along with the import directive.

No more action :global

If you have used the action :global do notation, this is replaced with the simpler use action do instead. Also, there is no more need for empty usage '', just delete it if you have it in your runfiles.

No more execute directive

If you have used it to cross-call other actions, it is no longer available. As an alternative, you can define common code in separate classes and require them, or use the new helpers directive to define functions that will be available to all actions.

Code outside of actions should be inside helpers

If your runfiles include other ruby code, especially def method, you should now use the new helpers block and tuck this code inside it.

No more need for trap(:INT)

If your old runfiles trap the Interrupt signal, there is no longer a need to do so, as it is trapped by default.

Colsole is included

If your runfiles required and include Colsole, there is no longer a need to do it. Colsole is bundled and available in actions.

Long flags before short flags

This is a cosmetic change for consistency. All generated output shows long flags before short flags --force, -f instead of -f, --force. Update your custom usage directives accordingly.

Examples no longer add implicit 'run'

If you were using the example directive, it will no longer add the initial run in front of your examples. Add it yourself. This is intended to allow providing more elaborate examples.

RunfileTasks

The runfile-tasks gem is also updated to 1.x, with a modified syntax. If you are using it, make sure to upgrade it as well.

Contributing / Support

If you experience any issue, have a question or a suggestion, or if you wish to contribute, feel free to open an issue.

runfile's People

Contributors

dannyben avatar depfu[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

runfile's Issues

Global shortcut does not work in named runfiles

Using this file:

# test.runfile
shortcut 'gg', 'greet --shout'

usage  'greet [--shout]'
action :greet do |args|
  p args
end

The help message shows the shortcut, but the shortcut does not work.

The problem is here, we probably need to use the full_name and match it with argv

shortcuts.each do |from, to|
return Shellwords.split(to) + argv[1..] if from == argv[0]
end

Collision with call DSL method

The DSL method call can sometimes interfere with normal ruby operation.

It seems to collide with the Proc#call in some rare cases, for example, when requiring mongoid.

Need to either remove it or rename it.

Workaround:

module Runfile
  remove_method :call
end

Add .runfile config

To specify (at least) where is the runfile folder for named runfiles.

This will be very handy in Rails applications.

Improve handling of `run make` when .runfile is present

The core command run make is creating a new Runfile if one is not present.
Since the addition of the .runfile option, I believe we should also consider its presence the same, and not create a runfile if .runfile is present.

With the current situation, the command run make is sort of "reserved" and cannot be used when .runfile is used.

  • Also consider renaming run make to run new
  • Also consider adding something like run new config that will create .runfile sample

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.