Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
08a488f5
Commit
08a488f5
authored
Oct 18, 2016
by
Matt Butcher
Committed by
GitHub
Oct 18, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1142 from ammeon/add-update
feat(helm): `--no-update` flag for `helm repo add`
parents
765da276
16436b56
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
5 deletions
+61
-5
repo_add.go
cmd/helm/repo_add.go
+39
-5
repo_add_test.go
cmd/helm/repo_add_test.go
+8
-0
repo.go
pkg/repo/repo.go
+14
-0
No files found.
cmd/helm/repo_add.go
View file @
08a488f5
...
...
@@ -28,10 +28,11 @@ import (
)
type
repoAddCmd
struct
{
name
string
url
string
home
helmpath
.
Home
out
io
.
Writer
name
string
url
string
home
helmpath
.
Home
out
io
.
Writer
noupdate
bool
}
func
newRepoAddCmd
(
out
io
.
Writer
)
*
cobra
.
Command
{
...
...
@@ -54,11 +55,19 @@ func newRepoAddCmd(out io.Writer) *cobra.Command {
return
add
.
run
()
},
}
f
:=
cmd
.
Flags
()
f
.
BoolVar
(
&
add
.
noupdate
,
"no-update"
,
false
,
"raise error if repo is already registered"
)
return
cmd
}
func
(
a
*
repoAddCmd
)
run
()
error
{
if
err
:=
addRepository
(
a
.
name
,
a
.
url
,
a
.
home
);
err
!=
nil
{
var
err
error
if
a
.
noupdate
{
err
=
addRepository
(
a
.
name
,
a
.
url
,
a
.
home
)
}
else
{
err
=
updateRepository
(
a
.
name
,
a
.
url
,
a
.
home
)
}
if
err
!=
nil
{
return
err
}
fmt
.
Fprintf
(
a
.
out
,
"%q has been added to your repositories
\n
"
,
a
.
name
)
...
...
@@ -91,3 +100,28 @@ func insertRepoLine(name, url string, home helmpath.Home) error {
})
return
f
.
WriteFile
(
home
.
RepositoryFile
(),
0644
)
}
func
updateRepository
(
name
,
url
string
,
home
helmpath
.
Home
)
error
{
cif
:=
home
.
CacheIndex
(
name
)
if
err
:=
repo
.
DownloadIndexFile
(
name
,
url
,
cif
);
err
!=
nil
{
return
err
}
return
updateRepoLine
(
name
,
url
,
home
)
}
func
updateRepoLine
(
name
,
url
string
,
home
helmpath
.
Home
)
error
{
cif
:=
home
.
CacheIndex
(
name
)
f
,
err
:=
repo
.
LoadRepositoriesFile
(
home
.
RepositoryFile
())
if
err
!=
nil
{
return
err
}
f
.
Update
(
&
repo
.
Entry
{
Name
:
name
,
URL
:
url
,
Cache
:
filepath
.
Base
(
cif
),
})
return
f
.
WriteFile
(
home
.
RepositoryFile
(),
0666
)
}
cmd/helm/repo_add_test.go
View file @
08a488f5
...
...
@@ -92,4 +92,12 @@ func TestRepoAdd(t *testing.T) {
if
!
f
.
Has
(
testName
)
{
t
.
Errorf
(
"%s was not successfully inserted into %s"
,
testName
,
hh
.
RepositoryFile
())
}
if
err
:=
updateRepository
(
testName
,
ts
.
URL
(),
hh
);
err
!=
nil
{
t
.
Errorf
(
"Repository was not updated: %s"
,
err
)
}
if
err
:=
addRepository
(
testName
,
ts
.
URL
(),
hh
);
err
==
nil
{
t
.
Errorf
(
"Duplicate repository name was added"
)
}
}
pkg/repo/repo.go
View file @
08a488f5
...
...
@@ -109,6 +109,20 @@ func (r *RepoFile) Add(re ...*Entry) {
r
.
Repositories
=
append
(
r
.
Repositories
,
re
...
)
}
// Update attempts to replace one or more repo entries in a repo file. If an
// entry with the same name doesn't exist in the repo file it will add it.
func
(
r
*
RepoFile
)
Update
(
re
...*
Entry
)
{
for
_
,
target
:=
range
re
{
for
j
,
repo
:=
range
r
.
Repositories
{
if
repo
.
Name
==
target
.
Name
{
r
.
Repositories
[
j
]
=
target
break
}
}
r
.
Add
(
target
)
}
}
// Has returns true if the given name is already a repository name.
func
(
r
*
RepoFile
)
Has
(
name
string
)
bool
{
for
_
,
rf
:=
range
r
.
Repositories
{
...
...
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