• Stars
    star
    192
  • Rank 195,209 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A small command-line interface framework.

Hi, I’m Claide, your command-line tool aide.

Build Status Gem Version

I was born out of a need for a simple option and command parser, while still providing an API that allows you to quickly create a full featured command-line interface.

Install

$ [sudo] gem install claide

Usage

For full documentation, on the API of CLAide, visit rubydoc.info.

Argument handling

At its core, a library, such as myself, needs to parse the parameters specified by the user.

Working with parameters is done through the CLAide::ARGV class. It takes an array of parameters and parses them as either flags, options, or arguments.

Parameter Description
--milk, --no-milk A boolean ‘flag’, which may be negated.
--sweetener=honey An ‘option’ consists of a key, a ‘=’, and a value.
tea An ‘argument’ is just a value.

Accessing flags, options, and arguments, with the following methods, will also remove the parameter from the remaining unprocessed parameters.

argv = CLAide::ARGV.new(['tea', '--no-milk', '--sweetener=honey'])
argv.shift_argument      # => 'tea'
argv.shift_argument      # => nil
argv.flag?('milk')       # => false
argv.flag?('milk')       # => nil
argv.option('sweetener') # => 'honey'
argv.option('sweetener') # => nil

In case the requested flag or option is not present, nil is returned. You can specify a default value to be used as the optional second method parameter:

argv = CLAide::ARGV.new(['tea'])
argv.flag?('milk', true)         # => true
argv.option('sweetener', 'sugar') # => 'sugar'

Unlike flags and options, accessing all of the arguments can be done in either a preserving or mutating way:

argv = CLAide::ARGV.new(['tea', 'coffee'])
argv.arguments  # => ['tea', 'coffee']
argv.arguments! # => ['tea', 'coffee']
argv.arguments  # => []

Command handling

Commands are actions that a tool can perform. Every command is represented by its own command class.

Commands may be nested, in which case they inherit from the ‘super command’ class. Some of these nested commands may not actually perform any work themselves, but are rather used as ‘super commands’ only, in which case they are ‘abtract commands’.

Running commands is typically done through the CLAide::Command.run(argv) method, which performs the following three steps:

  1. Parses the given parameters, finds the command class matching the parameters, and instantiates it with the remaining parameters. It’s each nested command class’ responsibility to remove the parameters it handles from the remaining parameters, before calling the super implementation.

  2. Asks the command instance to validate its parameters, but only after calling the super implementation. The super implementation will show a help banner in case the --help flag is specified, not all parameters were removed from the parameter list, or the command is an abstract command.

  3. Calls the run method on the command instance, where it may do its work.

  4. Catches any uncaught exception and shows it to user in a meaningful way.

    • A Help exception triggers a help banner to be shown for the command.
    • A exception that includes the InformativeError module will show only the message, unless disabled with the --verbose flag; and in red, depending on the color configuration.
    • Any other type of exception will be passed to Command.report_error(error) for custom error reporting (such as the one in CocoaPods).

In case you want to call commands from inside other commands, you should use the CLAide::Command.parse(argv) method to retrieve an instance of the command and call run on it. Unless you are using user-supplied parameters, there should not be a need to validate the parameters.

See the example for a illustration of how to define commands.

More Repositories

1

CocoaPods

The Cocoa Dependency Manager.
Ruby
14,382
star
2

Specs

The CocoaPods Master Repo
6,649
star
3

Xcodeproj

Create and modify Xcode projects from Ruby.
Ruby
2,287
star
4

CocoaPods-app

A full-featured and standalone installation of CocoaPods.
Swift
1,223
star
5

cocoapods-packager

CocoaPods plugin which allows you to generate a static library from a podspec.
Ruby
1,134
star
6

cocoapods-deintegrate

A CocoaPods plugin to remove and de-integrate CocoaPods from your project.
Ruby
1,073
star
7

Rome

Makes it easy to build a list of frameworks.
Ruby
696
star
8

Molinillo

A generic dependency resolution algorithm.
Ruby
412
star
9

pod-template

An opinionated template for creating a Pod.
Ruby
390
star
10

Rainforest

Automate the tasks necessary to develop on CocoaPods
Ruby
206
star
11

Core

The models used within the CocoaPods gem
Ruby
155
star
12

cocoapods-try

CocoaPods plugin which allows to quickly try the demo project of a Pod.
Ruby
131
star
13

cocoapods-acknowledgements

CocoaPods plugin that generates a plist which includes the installation metadata
Ruby
111
star
14

cocoadocs.org

Static generator for CocoaDocs.org
Ruby
95
star
15

CPDAcknowledgements

Show your CocoaPods dependencies in-app.
Objective-C
87
star
16

cocoapods-downloader

A small library that provides downloaders for various source types (HTTP/SVN/Git/Mercurial)
Ruby
81
star
17

cocoapods-plugins

Get info about available CocoaPods plugins.
Ruby
78
star
18

cocoapods.org

That website https://cocoapods.org/ - pretty useful
Slim
52
star
19

CocoaPodsExampleLibrary

A Simple Example Library for CocoaPods Best Practices
Objective-C
45
star
20

guides.cocoapods.org

The guides for CocoaPods
Ruby
45
star
21

Nanaimo

A native ruby implementation of ASCII plist parsing & serializing
Ruby
41
star
22

trunk.cocoapods.org

The authentication server for CocoaPods push
Ruby
37
star
23

blog.cocoapods.org

The blog for CocoaPods
HTML
34
star
24

cocoapods-appledoc

CocoaPods plugin which allows you to generate documentation for a pod spec using AppleDoc.
Ruby
33
star
25

fourflusher

A library for interacting with Xcode simulators.
Ruby
32
star
26

search.cocoapods.org

This is the CocoaPods search engine repo, please direct CocoaPods issues to the main CocoaPods repository.
Ruby
25
star
27

swift

Issue tracker for CocoaPods with Swift issues
23
star
28

cocoapods-integration-specs

The integration specs of CocoaPods
Objective-C
23
star
29

Cork

A delightful CLI UI module.
Ruby
22
star
30

cocoapods-metadata-service

A metadata generator service for GitHub projects
TypeScript
18
star
31

cocoapods-trunk

CocoaPods plugin for trunk
Ruby
17
star
32

metrics.cocoapods.org

The API for CocoaPods
Ruby
17
star
33

CocoaPods-objc

Provides support for working with CocoaPods from Objective-C.
Objective-C
16
star
34

cocoadocs-api

This is more of an API _for_ CocoaDocs to use than the other way around.
Ruby
15
star
35

cocoapods-search

CocoaPods plugin that allows you to search your pod spec repository for specific pods matching a query.
Ruby
14
star
36

Design

The design files for CocoaPods
13
star
37

cocoapods.github.com

User and developer documentation for CocoaPods
Ruby
12
star
38

cocoapods-docs

Simple gem which offers convenient access to the documentation of a Pod via cocoadocs.org.
Ruby
11
star
39

shared_resources

Shared resources for the cocoapods websites
HTML
11
star
40

cdn.cocoapods.org

The new CDN
Ruby
10
star
41

Strata

Automate the tasks necessary to develop on the CocoaPods websites
Ruby
10
star
42

cocoapods-plugin-template

Ruby
9
star
43

feeds.cocoapods.org

Feeds or newly published Pods.
Ruby
8
star
44

cocoapods-test

CocoaPods plugin to run tests for a Pod
Ruby
7
star
45

cocoapods-repo-shard

Shard a CocoaPods specs repository
Ruby
6
star
46

cocoapods-stats

Statistics plugin for CocoaPods
Ruby
6
star
47

cocoapods-podfile_info

Get your dependency info out
Ruby
5
star
48

cocoapods-regression

Automation harness for CocoaPods regression tests.
Ruby
5
star
49

VersionKit

Ruby
5
star
50

stats.cocoapods.org

A server for receiving statistics and migrating data into metrics.cocoapods.org
Ruby
5
star
51

trunk.cocoapods.org-api-doc

Documentation for the Trunk API
4
star
52

Resolver-Integration-Specs

Ruby
3
star
53

claide-completion

CLI completion plugin for CLAide.
Ruby
3
star
54

Old-Specs

3
star
55

indexer.cocoapods.org

Trunk 🛄 👉 Algolia ⏱ indexer
TypeScript
3
star
56

cocoapods-test-specs

The test specs of CocoaPods
Ruby
2
star
57

CDN-Specs

A jsDelivr CDN compatible version of the CocoaPods Specs repo
2
star
58

Humus

Handles database migrations and states for all CP web projects.
Ruby
2
star
59

peril-settings

Settings for CocoaPods' peril
TypeScript
2
star
60

cocoadocs-queue

Queues pods for the cocoadocs workers
Ruby
2
star
61

cdn-staging.cocoapods.org

Staging environment for cdn.cocoapods.org
Ruby
1
star