Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Reorganize packages and import gitdir as an example
Browse files Browse the repository at this point in the history
  • Loading branch information
luxas committed Aug 19, 2019
1 parent 9f031e0 commit 5282300
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 71 deletions.
8 changes: 8 additions & 0 deletions cmd/sample-app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"fmt"
"net/http"
"os"
"time"

"github.com/labstack/echo"
"github.com/sirupsen/logrus"
"github.com/weaveworks/gitops-toolkit/cmd/sample-app/apis/sample/scheme"
"github.com/weaveworks/gitops-toolkit/cmd/sample-app/client"
"github.com/weaveworks/gitops-toolkit/pkg/filter"
"github.com/weaveworks/gitops-toolkit/pkg/git/gitdir"
"github.com/weaveworks/gitops-toolkit/pkg/logs"
"github.com/weaveworks/gitops-toolkit/pkg/runtime"
"github.com/weaveworks/gitops-toolkit/pkg/storage/cache"
Expand All @@ -26,6 +28,12 @@ func main() {
}

func run() error {
// Construct the GitDirectory implementation which backs the storage
gitDir := gitdir.NewGitDirectory("https://github.com/luxas/ignite-gitops", "master", nil, 10*time.Second)

// Wait for the repo to be cloned
gitDir.WaitForClone()

ms, err := manifest.NewManifestStorage(ManifestDir, scheme.Serializer)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/gitops/gitdir/gitdir.go → pkg/git/gitdir/gitdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

log "github.com/sirupsen/logrus"
"github.com/weaveworks/gitops-toolkit/git"
"github.com/weaveworks/gitops-toolkit/pkg/git"
"github.com/weaveworks/gitops-toolkit/pkg/util"
)

Expand Down
33 changes: 0 additions & 33 deletions pkg/gitops/gitops.go

This file was deleted.

37 changes: 0 additions & 37 deletions pkg/util/fs.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package util

import (
"fmt"
"io"
"os"
)

Expand All @@ -23,38 +21,3 @@ func FileExists(filename string) bool {

return !info.IsDir()
}

func DirExists(dirname string) bool {
exists, info := PathExists(dirname)
if !exists {
return false
}

return info.IsDir()
}

func CopyFile(src string, dst string) error {
sourceFileStat, err := os.Stat(src)
if err != nil {
return err
}

if !sourceFileStat.Mode().IsRegular() {
return fmt.Errorf("%s is not a regular file", src)
}

source, err := os.Open(src)
if err != nil {
return err
}
defer source.Close()

destination, err := os.Create(dst)
if err != nil {
return err
}
defer destination.Close()

_, err = io.Copy(destination, source)
return err
}
13 changes: 13 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package util

import (
"bytes"
"fmt"
"os/exec"
"strings"
)

func ExecuteCommand(command string, args ...string) (string, error) {
cmd := exec.Command(command, args...)
out, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("command %q exited with %q: %v", cmd.Args, out, err)
}

return string(bytes.TrimSpace(out)), nil
}

func MatchPrefix(prefix string, fields ...string) ([]string, bool) {
var prefixMatches, exactMatches []string

Expand Down

0 comments on commit 5282300

Please sign in to comment.