-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making pod plugins
an abstract command with search as default subcommand
#13
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e7f13c0
Refactoring (#10) + Making `pod plugins` an abstract command (#11) wi…
AliSoftware 67a03da
Small fixes in spec (removed argv function, removed commented-out line)
AliSoftware 9728c69
Merge branch 'CocoaPods/master' into 'AliSoftware/master'
AliSoftware 6e81455
Improved help message a bit
AliSoftware 1d9eaa0
Added brackets around `QUERY` argument to let it show it's optional now.
AliSoftware 93fbea4
* Adding the 'list' subcommand, making it the default
AliSoftware 4fc74ca
Removed useless `require` statement
AliSoftware 55fe55f
small rdoc fixes
AliSoftware e1ddea1
I'm a perfectionist.
AliSoftware File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,87 @@ | ||
module Pod | ||
class Command | ||
class Plugins | ||
|
||
# The create subcommand. Used to create a new plugin using either the | ||
# default template (CocoaPods/cocoapods-plugin-template) or a custom | ||
# template | ||
# | ||
class Create < Plugins | ||
|
||
self.summary = 'Creates a new plugin' | ||
self.description = <<-DESC | ||
Creates a scaffold for the development of a new plugin according to the CocoaPods best practices. | ||
If a `TEMPLATE_URL`, pointing to a git repo containing a compatible template, is specified, it will be used in place of the default one. | ||
DESC | ||
|
||
self.arguments = 'NAME [TEMPLATE_URL]' | ||
|
||
def initialize(argv) | ||
@name = argv.shift_argument | ||
@template_url = argv.shift_argument | ||
super | ||
end | ||
|
||
def validate! | ||
super | ||
help! 'A name for the plugin is required.' if @name.nil? || @name.empty? | ||
help! 'The plugin name cannot contain spaces.' if @name.match(/\s/) | ||
end | ||
|
||
def run | ||
clone_template | ||
configure_template | ||
end | ||
|
||
#----------------------------------------# | ||
|
||
private | ||
|
||
# !@group Private helpers | ||
|
||
extend Executable | ||
executable :git | ||
executable :ruby | ||
|
||
TEMPLATE_REPO = 'https://github.com/CocoaPods/cocoapods-plugin-template.git' | ||
TEMPLATE_INFO_URL = 'https://github.com/CocoaPods/cocoapods-plugin-template' | ||
|
||
# Clones the template from the remote in the working directory using | ||
# the name of the plugin. | ||
# | ||
# @return [void] | ||
# | ||
def clone_template | ||
UI.section("Creating `#{@name}` plugin") do | ||
git! "clone '#{template_repo_url}' #{@name}" | ||
end | ||
end | ||
|
||
# Runs the template configuration utilities. | ||
# | ||
# @return [void] | ||
# | ||
def configure_template | ||
UI.section('Configuring template') do | ||
Dir.chdir(@name) do | ||
if File.file? 'configure' | ||
system "./configure #{@name}" | ||
else | ||
UI.warn 'Template does not have a configure file.' | ||
end | ||
end | ||
end | ||
end | ||
|
||
# Checks if a template URL is given else returns the TEMPLATE_REPO URL | ||
# | ||
# @return String | ||
# | ||
def template_repo_url | ||
@template_url || TEMPLATE_REPO | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'pod/plugins_helper' | ||
|
||
module Pod | ||
class Command | ||
class Plugins | ||
|
||
# The list subcommand. Used to list all known plugins | ||
# | ||
class List < Plugins | ||
|
||
self.summary = 'List all known plugins' | ||
self.description = <<-DESC | ||
List all known plugins (according to the list hosted on github.com/CocoaPods/cocoapods.org) | ||
DESC | ||
|
||
def self.options | ||
super.reject { |option, _| option == '--silent' } | ||
end | ||
|
||
def run | ||
plugins = PluginsHelper.known_plugins | ||
|
||
UI.title 'Available CocoaPods Plugins:' do | ||
plugins.each { |plugin| PluginsHelper.print_plugin plugin, self.verbose? } | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to port this logic to CLAide /c @alloy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, it’s quite simple to grasp if you know Ruby. What would you propose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Allow I agree that this is pretty annoying to have to
.concat(super).reject { }
every time we create a subcommand (to get the common options like--verbose
and--help
and all withArray#concat(super)
… but except some like--silent
in some cases withArray#reject
)Maybe we can have helper methods in
Pod::Command
if not inCLAide::Command
, likeself.common_options
(even with some parameter to handle multiple cases like commands designated to only output stuff and do nothing else, for which options like--silent
wouldn't have much sense), so that we couldArray#concat
with this instead ofsuper
?At least I'm sure it's worth thinking about sthg to avoid this
concat
+reject
pattern that we observe in a lot of pod subcommands.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it’s definitely worth it to create a CLAide ticket about it to remind us to reflect on this in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alloy @irrationalfab Ticket opened!