Skip to content

Commit

Permalink
Add support for kbrew registries (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrasadG193 authored Mar 23, 2021
1 parent 2ffb705 commit 49fc871
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16

- name: Build
run: go build -v ./...
Expand Down
58 changes: 34 additions & 24 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package main

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"fmt"
"strings"

homedir "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/kbrew-dev/kbrew/pkg/apps"
"github.com/kbrew-dev/kbrew/pkg/config"
"github.com/kbrew-dev/kbrew/pkg/registry"
)

var (
Expand Down Expand Up @@ -46,14 +45,35 @@ var (
Use: "search [NAME]",
Short: "Search application",
RunE: func(cmd *cobra.Command, args []string) error {
return apps.Search(args, configFile, namespace)
appName := ""
if len(args) != 0 {
appName = args[0]
}
reg, err := registry.New(config.ConfigDir)
if err != nil {
return err
}
appList, err := reg.Search(appName, false)
if err != nil {
return err
}
if len(appList) == 0 {
fmt.Printf("No recipe found for %s.\n", appName)
return nil
}
fmt.Println("Available recipes:")
for _, app := range appList {
fmt.Println(app.Name)
}
return nil
},
}
)

func init() {
cobra.OnInitialize(initConfig)
cobra.OnInitialize(config.InitConfig)
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "config file (default is $HOME/.kbrew.yaml)")
rootCmd.PersistentFlags().StringVarP(&config.ConfigDir, "config-dir", "", "", "config dir (default is $HOME/.kbrew)")
rootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "n", "", "namespace")

rootCmd.AddCommand(installCmd)
Expand All @@ -80,27 +100,17 @@ func checkArgs(args []string) error {
func manageApp(m apps.Method, args []string) error {
ctx := context.Background()
for _, a := range args {
reg, err := registry.New(config.ConfigDir)
if err != nil {
return err
}
configFile, err := reg.FetchRecipe(strings.ToLower(a))
if err != nil {
return err
}
if err := apps.Run(ctx, m, strings.ToLower(a), namespace, configFile); err != nil {
return err
}
}
return nil
}

func initConfig() {
if configFile != "" {
return
}
// Find home directory.
home, err := homedir.Dir()
cobra.CheckErr(err)

// Generate default config file path
configFile = filepath.Join(home, ".kbrew.yaml")
if _, err := os.Stat(configFile); os.IsNotExist(err) {
// Create file with default config
c := []byte("apiVersion: v1\nkind: kbrew\napps:\n")
err := ioutil.WriteFile(configFile, c, 0644)
cobra.CheckErr(err)
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module github.com/kbrew-dev/kbrew

go 1.15
go 1.16

replace github.com/graymeta/stow => github.com/kastenhq/stow v0.2.6-kasten.1

require (
github.com/go-git/go-git/v5 v5.2.0
github.com/kanisterio/kanister v0.0.0-20210224062123-08e898f3dbf3
github.com/mitchellh/go-homedir v1.1.0
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/openshift/api v0.0.0-20200526144822-34f54f12813a
github.com/openshift/client-go v0.0.0-20200521150516-05eb9880269c
github.com/pkg/errors v0.9.1
Expand Down
Loading

0 comments on commit 49fc871

Please sign in to comment.