Skip to content

Commit

Permalink
create internal/{apply,dyff,log}
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Mar 12, 2024
1 parent d0cb25c commit 987f974
Show file tree
Hide file tree
Showing 25 changed files with 475 additions and 370 deletions.
26 changes: 17 additions & 9 deletions cmd/timoni/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import (
"github.com/spf13/cobra"

apiv1 "github.com/stefanprodan/timoni/api/v1alpha1"
"github.com/stefanprodan/timoni/internal/apply"
"github.com/stefanprodan/timoni/internal/engine"
"github.com/stefanprodan/timoni/internal/engine/fetcher"
cueerrors "github.com/stefanprodan/timoni/internal/errors"
"github.com/stefanprodan/timoni/internal/flags"
"github.com/stefanprodan/timoni/internal/logger"
"github.com/stefanprodan/timoni/internal/runtime"
)

Expand Down Expand Up @@ -112,6 +114,8 @@ type applyFlags struct {

var applyArgs applyFlags

const ownershipConflictHint = "Apply with \"--overwrite-ownership\" to gain instance ownership."

func init() {
applyCmd.Flags().VarP(&applyArgs.version, applyArgs.version.Type(), applyArgs.version.Shorthand(), applyArgs.version.Description())
applyCmd.Flags().VarP(&applyArgs.pkg, applyArgs.pkg.Type(), applyArgs.pkg.Shorthand(), applyArgs.pkg.Description())
Expand Down Expand Up @@ -139,7 +143,7 @@ func runApplyCmd(cmd *cobra.Command, args []string) error {
applyArgs.name = args[0]
applyArgs.module = args[1]

log := LoggerInstance(cmd.Context(), applyArgs.name)
log := logger.LoggerInstance(cmd.Context(), applyArgs.name, true)

version := applyArgs.version.String()
if version == "" {
Expand Down Expand Up @@ -224,13 +228,17 @@ func runApplyCmd(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(cmd.Context(), rootArgs.timeout)
defer cancel()

opts := applyInstanceOptions{
rootDir: tmpDir,
dryrun: applyArgs.diff,
diff: applyArgs.diff,
wait: applyArgs.wait,
force: applyArgs.force,
overwriteOwnership: applyArgs.overwriteOwnership,
opts := apply.Options{
Dir: tmpDir,
DryRun: applyArgs.dryrun,
Diff: applyArgs.diff,
Wait: applyArgs.wait,
Force: applyArgs.force,
OverwriteOwnership: applyArgs.overwriteOwnership,
DiffOutput: cmd.OutOrStdout(),
KubeConfigFlags: kubeconfigArgs,
OwnershipConflictHint: ownershipConflictHint,
// ProgressStart: logger.StartSpinner,
}

bi := &engine.BundleInstance{
Expand All @@ -240,5 +248,5 @@ func runApplyCmd(cmd *cobra.Command, args []string) error {
Bundle: "",
}

return applyInstance(ctx, log, builder, buildResult, bi, opts, rootArgs.timeout)
return apply.ApplyInstance(ctx, log, builder, buildResult, bi, opts, rootArgs.timeout)
}
3 changes: 2 additions & 1 deletion cmd/timoni/artifact_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/spf13/cobra"

"github.com/stefanprodan/timoni/internal/flags"
"github.com/stefanprodan/timoni/internal/logger"
"github.com/stefanprodan/timoni/internal/oci"
)

Expand Down Expand Up @@ -64,7 +65,7 @@ func listArtifactCmdRun(cmd *cobra.Command, args []string) error {
}
ociURL := args[0]

spin := StartSpinner("fetching tags")
spin := logger.StartSpinner("fetching tags")
defer spin.Stop()

ctx, cancel := context.WithTimeout(cmd.Context(), rootArgs.timeout)
Expand Down
7 changes: 4 additions & 3 deletions cmd/timoni/artifact_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/spf13/cobra"

"github.com/stefanprodan/timoni/internal/flags"
"github.com/stefanprodan/timoni/internal/logger"
"github.com/stefanprodan/timoni/internal/oci"
)

Expand Down Expand Up @@ -105,7 +106,7 @@ func pullArtifactCmdRun(cmd *cobra.Command, args []string) error {
}
ociURL := args[0]

log := LoggerFrom(cmd.Context())
log := logger.LoggerFrom(cmd.Context())

if err := os.MkdirAll(pullArtifactArgs.output, os.ModePerm); err != nil {
return fmt.Errorf("invalid output path %s: %w", pullArtifactArgs.output, err)
Expand All @@ -125,7 +126,7 @@ func pullArtifactCmdRun(cmd *cobra.Command, args []string) error {
}
}

spin := StartSpinner("pulling artifact")
spin := logger.StartSpinner("pulling artifact")
defer spin.Stop()

ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
Expand All @@ -138,7 +139,7 @@ func pullArtifactCmdRun(cmd *cobra.Command, args []string) error {
}

spin.Stop()
log.Info(fmt.Sprintf("extracted: %s", colorizeSubject(pullArtifactArgs.output)))
log.Info(fmt.Sprintf("extracted: %s", logger.ColorizeSubject(pullArtifactArgs.output)))

return nil
}
9 changes: 5 additions & 4 deletions cmd/timoni/artifact_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
apiv1 "github.com/stefanprodan/timoni/api/v1alpha1"
"github.com/stefanprodan/timoni/internal/engine"
"github.com/stefanprodan/timoni/internal/flags"
"github.com/stefanprodan/timoni/internal/logger"
"github.com/stefanprodan/timoni/internal/oci"
)

Expand Down Expand Up @@ -118,7 +119,7 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
pushArtifactArgs.ignorePaths = append(pushArtifactArgs.ignorePaths, ps...)
}

log := LoggerFrom(cmd.Context())
log := logger.LoggerFrom(cmd.Context())
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel()

Expand All @@ -128,7 +129,7 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
}
oci.AppendGitMetadata(pushArtifactArgs.path, annotations)

spin := StartSpinner("pushing artifact")
spin := logger.StartSpinner("pushing artifact")
defer spin.Stop()

opts := oci.Options(ctx, pushArtifactArgs.creds.String(), rootArgs.registryInsecure)
Expand Down Expand Up @@ -164,8 +165,8 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
log.Info(fmt.Sprintf("artifact: %s", colorizeSubject(ociURL)))
log.Info(fmt.Sprintf("digest: %s", colorizeSubject(digest.DigestStr())))
log.Info(fmt.Sprintf("artifact: %s", logger.ColorizeSubject(ociURL)))
log.Info(fmt.Sprintf("digest: %s", logger.ColorizeSubject(digest.DigestStr())))

return nil
}
7 changes: 4 additions & 3 deletions cmd/timoni/artifact_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/spf13/cobra"

"github.com/stefanprodan/timoni/internal/flags"
"github.com/stefanprodan/timoni/internal/logger"
"github.com/stefanprodan/timoni/internal/oci"
)

Expand Down Expand Up @@ -62,10 +63,10 @@ func tagArtifactCmdRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("at least one tag is required")
}

spin := StartSpinner("tagging artifact")
spin := logger.StartSpinner("tagging artifact")
defer spin.Stop()

log := LoggerFrom(cmd.Context())
log := logger.LoggerFrom(cmd.Context())
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel()

Expand All @@ -86,7 +87,7 @@ func tagArtifactCmdRun(cmd *cobra.Command, args []string) error {
}

for _, tag := range tagArtifactArgs.tags {
log.Info(fmt.Sprintf("tagged: %s", colorizeSubject(fmt.Sprintf("%s:%s", baseURL, tag))))
log.Info(fmt.Sprintf("tagged: %s", logger.ColorizeSubject(fmt.Sprintf("%s:%s", baseURL, tag))))
}

return nil
Expand Down
Loading

0 comments on commit 987f974

Please sign in to comment.