-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
Dry::CLI::Namespace
, a class to group commands
- Loading branch information
1 parent
252a7c2
commit 6163287
Showing
6 changed files
with
152 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# frozen_string_literal: true | ||
|
||
module Dry | ||
class CLI | ||
# Base class for namespaces | ||
# | ||
# @since 1.1.1 | ||
class Namespace | ||
# @since 1.1.1 | ||
# @api private | ||
def self.inherited(base) | ||
super | ||
base.class_eval do | ||
@description = nil | ||
@examples = [] | ||
@arguments = [] | ||
@options = [] | ||
@subcommands = [] | ||
end | ||
base.extend ClassMethods | ||
end | ||
|
||
# @since 1.1.1 | ||
# @api private | ||
module ClassMethods | ||
# @since 1.1.1 | ||
# @api private | ||
attr_reader :description | ||
|
||
# @since 1.1.1 | ||
# @api private | ||
attr_reader :examples | ||
|
||
# @since 1.1.1 | ||
# @api private | ||
attr_reader :arguments | ||
|
||
# @since 1.1.1 | ||
# @api private | ||
attr_reader :options | ||
|
||
# @since 1.1.1 | ||
# @api private | ||
attr_accessor :subcommands | ||
end | ||
|
||
# Set the description of the namespace | ||
# | ||
# @param description [String] the description | ||
# | ||
# @since 1.1.1 | ||
# | ||
# @example | ||
# require "dry/cli" | ||
# | ||
# class YourNamespace < Dry::CLI::Namespace | ||
# desc "Collection of really useful commands" | ||
# | ||
# class YourCommand < Dry::CLI::Command | ||
# # ... | ||
# end | ||
# end | ||
def self.desc(description) | ||
@description = description | ||
end | ||
|
||
# @since 1.1.1 | ||
# @api private | ||
def self.default_params | ||
{} | ||
end | ||
|
||
# @since 1.1.1 | ||
# @api private | ||
def self.required_arguments | ||
[] | ||
end | ||
|
||
# @since 1.1.1 | ||
# @api private | ||
def self.subcommands | ||
subcommands | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters