Class: Pod::Command::Reopen

Inherits:
Pod::Command show all
Defined in:
lib/cocoapods-reopen/command/reopen.rb

Overview

TODO:

Create a PR to add your plugin to CocoaPods/cocoapods.org in the ‘plugins.json` file, once your plugin is released.

This is an example of a cocoapods plugin adding a top-level subcommand to the ‘pod’ command.

You can also create subcommands of existing or new commands. Say you wanted to add a subcommand to ‘list` to show newly deprecated pods, (e.g. `pod list deprecated`), there are a few things that would need to change.

  • move this file to ‘lib/pod/command/list/deprecated.rb` and update the class to exist in the the Pod::Command::List namespace

  • change this class to extend from ‘List` instead of `Command`. This tells the plugin system that it is a subcommand of `list`.

  • edit ‘lib/cocoapods_plugins.rb` to require this file

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Reopen

Returns a new instance of Reopen.



27
28
29
30
# File 'lib/cocoapods-reopen/command/reopen.rb', line 27

def initialize(argv)
  @workspace = find_workspace_in(Pathname.pwd)
  super
end

Instance Method Details

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cocoapods-reopen/command/reopen.rb', line 37

def run
  ascript = <<~STR.strip_heredoc
    tell application "Xcode"
            set docs to (document of every window)
            repeat with doc in docs
                if class of doc is workspace document then
                    set docPath to path of doc
                    if docPath begins with "#{@workspace}" then
                        log docPath
                        close doc
                        return
                    end if
                end if
            end repeat
    end tell
  STR
  `osascript -e '#{ascript}'`
  `open "#{@workspace}"`
end

#validate!Object

Raises:

  • (Informative)


32
33
34
35
# File 'lib/cocoapods-reopen/command/reopen.rb', line 32

def validate!
  super
  raise Informative, 'No xcode workspace found' unless @workspace
end