GithubHelp home page GithubHelp logo

bhanditz / clamp-completer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kontena/clamp-completer

0.0 1.0 0.0 22 KB

Automatically generate shell autocompletion scripts for clamp based ruby CLI tools

License: Apache License 2.0

Ruby 36.26% HTML 63.74%

clamp-completer's Introduction

Build Status Gem Version

Clamp::Completer

Automatically generate shell auto-completion scripts for Ruby command-line tools built using the clamp gem.

Installation

Add this line to your application's Gemfile:

gem 'clamp-completer'

Or install it yourself as:

$ gem install clamp-completer

Usage

Require the clamp/completer and in your application's root command, add a subcommand:

require 'clamp/completer'

Clamp do
  subcommand "complete", "shell autocompletions", Clamp::Completer.new(self)
end

This will add a complete subcommand:

$ your_app complete zsh
$ your_app complete bash

You can redirect the output to a static file or load the output directly into the running environment:

# zsh / bash:
$ source <(your_app complete)
# or for the macOs preinstalled bash version:
$ source /dev/stdin <<<"$(your_app complete bash)"

Customizing completions

Currently, subcommand completions and flag-type options defined through option '--debug', :flag, 'enable debug' should work correctly out-of-the-box. For options that take parameters, such as file paths or a predefined set of words, you can define methods on your command classes that will be used to determine how the values should be completed:

Clamp do
  option '--config', 'YAML_FILE', "configuration YAML file path"

  def complete_yaml_file # name derived from the YAML_FILE argument description
    { glob: '*.yml' }
  end
end
Clamp do
  option '--role', 'ROLE_NAME', "node role"

  def complete_role # name derived from the attribute name
    "master worker" # will add "master" and "worker" as completion responses when you do: your_app --role <tab>
  end
end

Completion method response types

String

A space separated string of possible values for the option

Symbol

Currently known symbols:

  • :dirs will complete directory names
  • :files will complete file names
  • :hosts will complete known host names
Hash

Much like the Symbols, but returned in Hash format to enable passing options:

  • { glob: '*.yml' } will complete files endinging with .yml
  • { command: 'cut -d':' -f1 /etc/passwd' } will run a command to get completion candidates, in this case the usernames from /etc/password

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/clamp-completer.

clamp-completer's People

Contributors

kke avatar

Watchers

 avatar

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.