-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
325 changed files
with
1,219 additions
and
72,980 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright © 2020 NAME HERE <EMAIL ADDRESS> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// helmCmd represents the helm command | ||
var helmCmd = &cobra.Command{ | ||
Use: "helm", | ||
Short: "Tools to interact with helm", | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(helmCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// helmCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// helmCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
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,66 @@ | ||
/* | ||
Copyright © 2020 NAME HERE <EMAIL ADDRESS> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/redradrat/kable/kable/concepts" | ||
|
||
"github.com/redradrat/kable/kable/helm" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var subdir string | ||
|
||
// helmImportCmd represents the import command | ||
var helmImportCmd = &cobra.Command{ | ||
Use: "import", | ||
Short: "Import a helm chart from a git repo into the concept (need to be in directory of the concept", | ||
Example: "kable helm import https://github.com/helm/charts --subdir stable/sentry", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
return errors.New("requires exactly ONE argument") | ||
} | ||
return nil | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if _, err := concepts.GetConcept("."); err != nil { | ||
PrintError("current directory is not a concept directory: %s", err) | ||
} | ||
PrintMsg("Importing helm chart '%s' into current concept...", filepath.Base(filepath.Join(strings.TrimSuffix(args[0], ".git"), subdir))) | ||
if err := helm.ImportHelmChart(helm.HelmChart{URL: args[0], Subdir: &subdir}, "."); err != nil { | ||
PrintError("unable to import helm chart: %s", err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
helmCmd.AddCommand(helmImportCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// helmImportCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
helmImportCmd.Flags().StringVarP(&subdir, "subdir", "s", "", "The subdirectory in the repo, where the chart resides.") | ||
} |
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
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,34 @@ | ||
package helm | ||
|
||
import ( | ||
"github.com/go-git/go-git/v5" | ||
) | ||
|
||
// Checks out the given repository to the given directory and returns the path | ||
func Checkout(url, path string) error { | ||
repo, err := git.PlainOpen(path) | ||
missing := err == git.ErrRepositoryNotExists | ||
if err != nil && !missing { | ||
return err | ||
} | ||
|
||
if !missing { | ||
wt, err := repo.Worktree() | ||
if err != nil { | ||
return err | ||
} | ||
if err := wt.Pull(&git.PullOptions{}); err != nil && err != git.NoErrAlreadyUpToDate { | ||
return err | ||
} | ||
} else { | ||
_, err := git.PlainClone(path, false, &git.CloneOptions{ | ||
URL: url, | ||
SingleBranch: true, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.