Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
5e81227e
Commit
5e81227e
authored
May 26, 2013
by
Marin Usalj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add command for manipulating pod path config
parent
23abea78
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
205 additions
and
2 deletions
+205
-2
command.rb
lib/cocoapods/command.rb
+2
-1
config.rb
lib/cocoapods/command/config.rb
+115
-0
resolver.rb
lib/cocoapods/resolver.rb
+1
-1
config_spec.rb
spec/functional/command/config_spec.rb
+86
-0
command_spec.rb
spec/unit/command_spec.rb
+1
-0
No files found.
lib/cocoapods/command.rb
View file @
5e81227e
...
@@ -14,6 +14,7 @@ module Pod
...
@@ -14,6 +14,7 @@ module Pod
require
'cocoapods/command/list'
require
'cocoapods/command/list'
require
'cocoapods/command/outdated'
require
'cocoapods/command/outdated'
require
'cocoapods/command/podfile_info'
require
'cocoapods/command/podfile_info'
require
'cocoapods/command/config'
require
'cocoapods/command/project'
require
'cocoapods/command/project'
require
'cocoapods/command/push'
require
'cocoapods/command/push'
require
'cocoapods/command/repo'
require
'cocoapods/command/repo'
...
@@ -87,7 +88,7 @@ module Pod
...
@@ -87,7 +88,7 @@ module Pod
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------#
include
Config
::
Mixin
include
Pod
::
Config
::
Mixin
private
private
...
...
lib/cocoapods/command/config.rb
0 → 100644
View file @
5e81227e
module
Pod
class
Command
# This command was made in first place for supporting local repos.
# Command uses file ~/.config/cocoapods
#
# Sample usage:
# pod config --local ObjectiveSugar ~/code/OSS/ObjectiveSugar
# pod config --global ObjectiveRecord ~/code/OSS/ObjectiveRecord
#
# pod config --delete --local ObjectiveSugar
# pod config --delete --global ObjectiveSugar
#
# For both storing and deleting, --local is default and it can be ommitted
# pod config Kiwi ~/code/OSS/Kiwi
# pod config --delete Kiwi
#
class
Config
<
Command
CONFIG_FILE_PATH
=
File
.
expand_path
(
'~/.config/cocoapods'
)
LOCAL_OVERRIDES
=
'PER_PROJECT_REPO_OVERRIDES'
GLOBAL_OVERRIDES
=
'GLOBAL_REPO_OVERRIDES'
self
.
summary
=
'Something like `bundle config` ... but better.'
self
.
description
=
<<-
DESC
Use `pod config` when you're developing a pod that uses another pod of yours.
This way you will reference it locally without modifying a Podfile.
DESC
self
.
arguments
=
'[pod name] [--local, --global, --delete] [path]'
def
initialize
(
argv
)
@global
=
argv
.
flag?
(
'global'
)
@local
=
argv
.
flag?
(
'local'
)
||
!
@global
@should_delete
=
argv
.
flag?
(
'delete'
)
@pod_name
=
argv
.
shift_argument
@pod_path
=
argv
.
shift_argument
super
end
def
self
.
options
[[
'--local'
,
'Uses the local pod for the current project only'
],
[
'--global'
,
'Uses the local pod everywhere'
],
[
'--delete'
,
'Removes the local pod from configuration'
]]
end
def
run
help!
unless
args_are_valid?
update_config
end
private
def
args_are_valid?
valid
=
!!
@pod_name
valid
&=
!!
@pod_path
unless
@should_delete
valid
end
def
update_config
if
@should_delete
@local
?
delete_local_config
:
delete_global_config
else
@local
?
store_local_config
:
store_global_config
end
write_config_to_file
end
def
store_global_config
config_hash
[
GLOBAL_OVERRIDES
][
@pod_name
]
=
@pod_path
end
def
store_local_config
config_hash
[
LOCAL_OVERRIDES
][
project_name
]
||=
{}
config_hash
[
LOCAL_OVERRIDES
][
project_name
][
@pod_name
]
=
@pod_path
end
def
delete_local_config
config_hash
[
LOCAL_OVERRIDES
][
project_name
].
delete
(
@pod_name
)
end
def
delete_global_config
config_hash
[
GLOBAL_OVERRIDES
].
delete
(
@pod_name
)
end
def
config_hash
@config_hash
||=
load_config
end
def
load_config
FileUtils
.
touch
(
CONFIG_FILE_PATH
)
unless
File
.
exists?
CONFIG_FILE_PATH
config
=
YAML
.
load
(
File
.
open
(
CONFIG_FILE_PATH
))
||
{}
config
[
LOCAL_OVERRIDES
]
||=
{}
config
[
GLOBAL_OVERRIDES
]
||=
{}
config
end
def
project_name
`basename
#{
Dir
.
pwd
}
`
.
chomp
end
def
write_config_to_file
File
.
write
(
CONFIG_FILE_PATH
,
config_hash
.
delete_blank
.
to_yaml
)
end
end
end
end
class
Hash
def
delete_blank
delete_if
{
|
k
,
v
|
v
.
empty?
or
v
.
instance_of?
(
Hash
)
&&
v
.
delete_blank
.
empty?
}
end
end
lib/cocoapods/resolver.rb
View file @
5e81227e
...
@@ -170,7 +170,7 @@ module Pod
...
@@ -170,7 +170,7 @@ module Pod
end
end
end
end
# Loads or returns a previously initialized for the Pod of the given
# Loads or returns a previously initialized
Set
for the Pod of the given
# dependency.
# dependency.
#
#
# @param [Dependency] dependency
# @param [Dependency] dependency
...
...
spec/functional/command/config_spec.rb
0 → 100644
View file @
5e81227e
require
File
.
expand_path
(
'../../../spec_helper'
,
__FILE__
)
require
'yaml'
module
Pod
describe
Command
::
Config
do
extend
SpecHelper
::
TemporaryRepos
LOCAL_OVERRIDES
=
'PER_PROJECT_REPO_OVERRIDES'
GLOBAL_OVERRIDES
=
'GLOBAL_REPO_OVERRIDES'
pod_name
=
'ObjectiveSugar'
pod_path
=
'~/code/OSS/ObjectiveSugar'
project_name
=
'SampleProject'
before
do
Config
.
instance
=
nil
def
Dir
.
pwd
;
'~/code/OSS/SampleProject'
;
end
@config_file_path
=
temporary_directory
+
"mock_config"
Command
::
Config
.
send
(
:remove_const
,
'CONFIG_FILE_PATH'
)
Command
::
Config
.
const_set
(
"CONFIG_FILE_PATH"
,
@config_file_path
)
end
it
"writes local repos for each project"
do
run_command
(
'config'
,
"--local"
,
pod_name
,
pod_path
)
yaml
=
YAML
.
load
(
File
.
open
(
@config_file_path
))
yaml
[
LOCAL_OVERRIDES
][
project_name
][
pod_name
].
should
.
equal
pod_path
end
it
"writes global repos without specifying project"
do
run_command
(
'config'
,
"--global"
,
pod_name
,
pod_path
)
yaml
=
YAML
.
load
(
File
.
open
(
@config_file_path
))
yaml
[
GLOBAL_OVERRIDES
][
pod_name
].
should
.
equal
pod_path
end
it
"defaults to local scope"
do
run_command
(
'config'
,
pod_name
,
pod_path
)
yaml
=
YAML
.
load
(
File
.
open
(
@config_file_path
))
yaml
[
LOCAL_OVERRIDES
][
project_name
][
pod_name
].
should
.
equal
pod_path
end
it
"raises help! if invalid args are provided"
do
[
lambda
{
run_command
(
"config"
,
'ObjectiveSugar'
)
},
lambda
{
run_command
(
"config"
,
"--local"
,
'ObjectiveSugar'
)
},
lambda
{
run_command
(
"config"
,
"--global"
,
'ObjectiveSugar'
)
},
lambda
{
run_command
(
"config"
,
'~/code/OSS/ObjectiveSugar'
)
},
]
.
each
{
|
invalid
|
invalid
.
should
.
raise
CLAide
::
Help
}
end
it
"deletes local configuration by default"
do
run_command
(
'config'
,
"--global"
,
pod_name
,
pod_path
)
run_command
(
'config'
,
"--local"
,
pod_name
,
pod_path
)
run_command
(
'config'
,
"--delete"
,
pod_name
)
yaml
=
YAML
.
load
(
File
.
open
(
@config_file_path
))
yaml
.
should
.
not
.
has_key?
LOCAL_OVERRIDES
yaml
[
GLOBAL_OVERRIDES
][
pod_name
].
should
.
equal
pod_path
end
it
"deletes global configuration"
do
run_command
(
'config'
,
"--global"
,
pod_name
,
pod_path
)
run_command
(
'config'
,
"--global"
,
"--delete"
,
pod_name
)
yaml
=
YAML
.
load
(
File
.
open
(
@config_file_path
))
yaml
.
should
.
not
.
has_key?
GLOBAL_OVERRIDES
end
end
end
# ===================
# Config file format
# ===================
#
# ---
# LOCAL_OVERRIDES:
# SampleApp:
# ARAnalytics: ~/code/ARAnalytics
#
# GLOBAL_OVERRIDES:
# ObjectiveRecord: ~/code/OSS/ObjectiveRecord
# ObjectiveSugar: ~/code/OSS/ObjectiveSugar
#
spec/unit/command_spec.rb
View file @
5e81227e
...
@@ -3,6 +3,7 @@ require File.expand_path('../../spec_helper', __FILE__)
...
@@ -3,6 +3,7 @@ require File.expand_path('../../spec_helper', __FILE__)
module
Pod
module
Pod
describe
Command
do
describe
Command
do
it
"returns the proper command class"
do
it
"returns the proper command class"
do
Command
.
parse
(
%w{ config }
).
should
.
be
.
instance_of
Command
::
Config
Command
.
parse
(
%w{ help }
).
should
.
be
.
instance_of
Command
::
Help
Command
.
parse
(
%w{ help }
).
should
.
be
.
instance_of
Command
::
Help
Command
.
parse
(
%w{ install }
).
should
.
be
.
instance_of
Command
::
Install
Command
.
parse
(
%w{ install }
).
should
.
be
.
instance_of
Command
::
Install
Command
.
parse
(
%w{ list }
).
should
.
be
.
instance_of
Command
::
List
Command
.
parse
(
%w{ list }
).
should
.
be
.
instance_of
Command
::
List
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment