52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
|
gitPkg "coopcloud.tech/abra/pkg/git"
|
|
"coopcloud.tech/abra/pkg/log"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var AppDiffCommand = &cobra.Command{
|
|
Use: "diff <app> [flags]",
|
|
Aliases: []string{"df"},
|
|
Short: "Show diff of app env changes",
|
|
Long: `This command requires /usr/bin/git.`,
|
|
Example: " abra app diff 1312.net",
|
|
Args: cobra.ExactArgs(1),
|
|
ValidArgsFunction: func(
|
|
cmd *cobra.Command,
|
|
args []string,
|
|
toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
return autocomplete.AppNameComplete()
|
|
},
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
app := internal.ValidateApp(args)
|
|
|
|
gitDir := gitPkg.FindDir(app.Path)
|
|
if gitDir == "" {
|
|
log.Fatal(fmt.Errorf("no git repo found for %s", app.Name))
|
|
}
|
|
|
|
fpath := app.Path
|
|
realPath, err := filepath.EvalSymlinks(fpath)
|
|
if err != nil {
|
|
log.Fatalf("unable to app env: broken symlink: %s", fpath)
|
|
}
|
|
fpath = realPath
|
|
|
|
diff, err := gitPkg.DiffUnstaged(gitDir, fpath)
|
|
if err != nil {
|
|
log.Fatalf("unable to diff %s: %s", app.Name, err)
|
|
}
|
|
|
|
if diff != "" {
|
|
fmt.Print(diff)
|
|
}
|
|
},
|
|
}
|