Skip to content

Commit

Permalink
move to icons and fix paths
Browse files Browse the repository at this point in the history
  • Loading branch information
costaluu committed Sep 14, 2024
1 parent 2b3922f commit 9ac9171
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 41 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ jobs:
cd $GIT_WORKSPACE/src # Change to the src directory
# Build for Linux
GOOS=linux GOARCH=amd64 go build -o $OUTPUT_DIR/linux/$BINARY_NAME
GOOS=linux GOARCH=amd64 go build -trimpath -o $OUTPUT_DIR/linux/$BINARY_NAME
# Build for macOS
GOOS=darwin GOARCH=amd64 go build -o $OUTPUT_DIR/macos/$BINARY_NAME
GOOS=darwin GOARCH=amd64 go build -trimpath -o $OUTPUT_DIR/macos/$BINARY_NAME
# Build for Windows
GOOS=windows GOARCH=amd64 go build -o $OUTPUT_DIR/windows/$BINARY_NAME.exe
GOOS=windows GOARCH=amd64 go build -trimpath -o $OUTPUT_DIR/windows/$BINARY_NAME.exe
# Zip only the linux, macos, and windows folders without the full path
cd $OUTPUT_DIR
Expand Down
2 changes: 1 addition & 1 deletion src/bubbletea/components/filepickerlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type FileListItem struct {
}

func (i FileListItem) Title() string {
return fmt.Sprintf("%s %s", i.ItemTitle, constants.FileMark.Render())
return fmt.Sprintf("%s %s", i.ItemTitle, constants.FileMark)
}

func (i FileListItem) Description() string { return i.Desc }
Expand Down
11 changes: 7 additions & 4 deletions src/bubbletea/conflict/conflict.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math"
"os"
"path/filepath"
"regexp"
"strings"
"sync"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/costaluu/flag/bubbletea/custom/textarea"
"github.com/costaluu/flag/constants"
filesystem "github.com/costaluu/flag/fs"
"github.com/costaluu/flag/git"
"github.com/costaluu/flag/logger"
"github.com/costaluu/flag/resolver"
"github.com/costaluu/flag/types"
Expand Down Expand Up @@ -466,7 +468,7 @@ func (m model) View() string {
helpText += lipgloss.NewStyle().Foreground(lipgloss.Color("240")).SetString("• " + key.Help().Key).Render() + " " + key.Help().Desc + "\n"
}

return constants.MergeMark.Render() + " " + lipgloss.NewStyle().SetString(m.title).Bold(true).Render() + "\n" + lipgloss.JoinHorizontal(lipgloss.Top, m.input.View(), " ", helpText)
return constants.MergeMark + " " + lipgloss.NewStyle().SetString(m.title).Bold(true).Render() + "\n" + lipgloss.JoinHorizontal(lipgloss.Top, m.input.View(), " ", helpText)
}

func SolveConflicts(content []resolver.ConflictRecord, conflictPath string, title string) []resolver.ConflictRecord {
Expand Down Expand Up @@ -545,14 +547,15 @@ func FindGitConflicts(filePath string) ([]resolver.ConflictRecord) {
}

func Resolve(title string) {
var rootDir string = git.GetRepositoryRoot()
// var iterator int = 0
var allConflictsSolved bool = false

for !allConflictsSolved {
// iterator++

conflicts := FindGitConflicts("../.features/merge-tmp")
processedConflicts := SolveConflicts(conflicts, "../.features/merge-tmp", title)
conflicts := FindGitConflicts(filepath.Join(rootDir, ".features", "merge-tmp"))
processedConflicts := SolveConflicts(conflicts, filepath.Join(rootDir, ".features", "merge-tmp"), title)
var solvedConflicts []resolver.ConflictRecord
var unSolvedConflicts []resolver.ConflictRecord

Expand All @@ -569,7 +572,7 @@ func Resolve(title string) {
for _, solvedConflict := range solvedConflicts {
stringContent := strings.Split(solvedConflict.Current.Content, "\n")

err := filesystem.FileReplaceLinesInFile("../.features/merge-tmp", solvedConflict.Current.LineStart + lineOffset, solvedConflict.Current.LineEnd + lineOffset, stringContent)
err := filesystem.FileReplaceLinesInFile(filepath.Join(rootDir, ".features", "merge-tmp"), solvedConflict.Current.LineStart + lineOffset, solvedConflict.Current.LineEnd + lineOffset, stringContent)

if err != nil {
logger.Fatal[error](err)
Expand Down
4 changes: 2 additions & 2 deletions src/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var (

var (
AccentColor = "#f97900"
MergeMark = lipgloss.NewStyle().Foreground(lipgloss.Color(AccentColor)).SetString("⮂")
FileMark = lipgloss.NewStyle().Foreground(lipgloss.Color("166")).SetString("🗎")
MergeMark = "🔁"
FileMark = "📄"
CheckMark = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).SetString("✓")
XMark = lipgloss.NewStyle().Foreground(lipgloss.Color("160")).SetString("⨯")
InfoMark = lipgloss.NewStyle().Foreground(lipgloss.Color("31")).SetString("ⓘ")
Expand Down
29 changes: 12 additions & 17 deletions src/core/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ToggleCommitFeature(featureName string, state string) {
}

if !foundFeature {
logger.Info[string](fmt.Sprintf("Feature %s does not exists o"))
logger.Result[string](fmt.Sprintf("feature %s does not exists", featureName))
}

for path, features := range commitsSet {
Expand Down Expand Up @@ -200,8 +200,7 @@ func CommitUpdateBase(path string, finalMessage bool) {
baseExists := filesystem.FileFolderExists(filepath.Join(rootDir, ".features", "commits", normalizedPath))

if !baseExists {
logger.Info[string](fmt.Sprintf("%s is not a base file", path))
os.Exit(0)
logger.Result[string](fmt.Sprintf("%s is not a base file", path))
}

filesystem.FileCopy(filepath.Join(rootDir, path), filepath.Join(rootDir, ".features", "commits", normalizedPath, "base"))
Expand All @@ -227,8 +226,7 @@ func CommitBase(path string, skipForm bool) {
baseExists := filesystem.FileFolderExists(filepath.Join(rootDir, ".features", "commits", normalizedPath))

if baseExists {
logger.Info[string](fmt.Sprintf("%s is already a base commit", path))
os.Exit(0)
logger.Result[string](fmt.Sprintf("%s is already a base commit", path))
}

if !skipForm {
Expand Down Expand Up @@ -341,7 +339,7 @@ func CommitSaveToCurrentState(path string) {
_, checksum, exists := workingtree.FindKeyValue(filepath.Join(rootDir, ".features", "commits", normalizedPath), workingtree.StringToStringSlice(key))

if !exists {
logger.Fatal[string]("Could not found state")
logger.Result[string]("Could not found state")
}

workingtree.Remove(filepath.Join(rootDir, ".features", "commits", normalizedPath), key)
Expand Down Expand Up @@ -432,7 +430,7 @@ func CommitSave(path string, finalMessage bool) {
_, checksum, exists := workingtree.FindKeyValue(filepath.Join(rootDir, ".features", "commits", normalizedPath), workingtree.StringToStringSlice(selected.ItemValue))

if !exists {
logger.Fatal[string]("Could not found state")
logger.Result[string]("Could not found state")
}

workingtree.Remove(filepath.Join(rootDir, ".features", "commits", normalizedPath), selected.ItemValue)
Expand Down Expand Up @@ -567,8 +565,7 @@ func BuildBaseForFile(path string) {
baseExists := filesystem.FileFolderExists(filepath.Join(rootDir, ".features", "commits", normalizedPath))

if !baseExists {
logger.Info[string](fmt.Sprintf("%s is not a base file", path))
os.Exit(0)
logger.Result[string](fmt.Sprintf("%s is not a base file", path))
}

featuresTurnedOn := GetCommitFeaturesFromPath(normalizedPath)
Expand Down Expand Up @@ -597,7 +594,7 @@ func BuildBaseForFile(path string) {
tempStateCheckSum, exists := tree[nearPrefixKey]

if !exists {
logger.Fatal[string]("Build base: couldn't find temp state")
logger.Result[string]("Build base: couldn't find temp state")
}

var tempStateName string
Expand All @@ -623,7 +620,7 @@ func BuildBaseForFile(path string) {
soloFeatureCheckSum, exists := tree[fmt.Sprintf("[%s]", featureRemainingId)]

if !exists {
logger.Fatal[string]("Build base: couldn't find feature for building temp state")
logger.Result[string]("Build base: couldn't find feature for building temp state")
}

var featureName string = ""
Expand All @@ -636,7 +633,7 @@ func BuildBaseForFile(path string) {
}

if featureName == "" {
logger.Fatal[string]("Build base: couldn't find feature name for building temp state")
logger.Result[string]("Build base: couldn't find feature name for building temp state")
}

styledTempStateName := lipgloss.NewStyle().Foreground(lipgloss.Color(constants.AccentColor)).SetString(tempStateName).Bold(true)
Expand Down Expand Up @@ -687,8 +684,7 @@ func LookForChangesInBase(path string) bool {
baseExists := filesystem.FileFolderExists(filepath.Join(rootDir, ".features", "commits", normalizedPath))

if !baseExists {
logger.Info[string](fmt.Sprintf("%s is not a base file", path))
os.Exit(0)
logger.Result[string](fmt.Sprintf("%s is not a base file", path))
}

featuresTurnedOn := GetCommitFeaturesFromPath(normalizedPath)
Expand All @@ -714,7 +710,7 @@ func LookForChangesInBase(path string) bool {
_, currentStateCheckSum, exists := workingtree.FindKeyValue(filepath.Join(rootDir, ".features", "commits", normalizedPath), currentStateFeatures)

if !exists {
logger.Fatal[string]("Can not find current state")
logger.Result[string]("Can not find current state")
}

currentCheckSum := filesystem.FileGenerateCheckSum(filepath.Join(rootDir, path))
Expand All @@ -737,8 +733,7 @@ func RebaseFile(path string, finalMessage bool) {
baseExists := filesystem.FileFolderExists(filepath.Join(rootDir, ".features", "commits", normalizedPath))

if !baseExists {
logger.Info[string](fmt.Sprintf("%s is not a base file", path))
os.Exit(0)
logger.Result[string](fmt.Sprintf("%s is not a base file", path))
}

tree := workingtree.LoadWorkingTree(filepath.Join(rootDir, ".features", "commits", normalizedPath))
Expand Down
6 changes: 3 additions & 3 deletions src/core/delimeters.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ReadDelimeters() types.Delimeters {

var delimeters types.Delimeters

filesystem.FileReadJSONFromFile(filepath.Join(rootDir, ".features/delimeters"), &delimeters)
filesystem.FileReadJSONFromFile(filepath.Join(rootDir, ".features", "delimeters"), &delimeters)

return delimeters
}
Expand All @@ -38,7 +38,7 @@ func SetDelimeter(extension string, start string, end string) {

var rootDir string = git.GetRepositoryRoot()

filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features/delimeters"), delimeters)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "delimeters"), delimeters)
}

func DeleteDelimeter(extension string) {
Expand All @@ -54,7 +54,7 @@ func DeleteDelimeter(extension string) {

var rootDir string = git.GetRepositoryRoot()

filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features/delimeters"), delimeters)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "delimeters"), delimeters)
}

func ListDelimeters() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func CreateNewWorkspace() {
},
}

filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features/delimeters"), delimeters)
filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "delimeters"), delimeters)

logger.Success[string]("folder .features created!")
}
Expand Down
2 changes: 1 addition & 1 deletion src/git/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Merge3Way(fileAPath string, fileBasePath string, fileBPath string, featureA
logger.Fatal[error](err)
}

filesystem.FileWrite(result.Result, filepath.Join(repoRoot, ".features/merge-tmp"))
filesystem.FileWrite(result.Result, filepath.Join(repoRoot, ".features", "merge-tmp"))

return result.Conflicts
}
Expand Down
14 changes: 6 additions & 8 deletions src/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,34 @@ import (
"fmt"
"os"
"runtime/debug"

"github.com/costaluu/flag/constants"
)

func Info[T any](msg T) {
fmt.Printf("ℹ️ %v\n", msg)
fmt.Printf("🔎 %v\n", msg)
}

func Result[T any](msg T) {
fmt.Printf("ℹ️ %v\n", msg)
fmt.Printf("🔎 %v\n", msg)
os.Exit(0)
}

func Error[T any](msg T) {
fmt.Printf("%s %v\n", constants.XMark.Render(), msg)
fmt.Printf(" %v\n", msg)
debug.PrintStack()
}

func Fatal[T any](msg T) {
fmt.Printf("%s %v\n", constants.XMark.Render(), msg)
fmt.Printf(" %v\n", msg)
debug.PrintStack()
os.Exit(0)
}

func Warning[T any](msg T) {
fmt.Printf("%s %v\n", constants.WarningMark.Render(), msg)
fmt.Printf("🚨 %v\n", msg)
}

func Success[T any](msg T) {
fmt.Printf("%s %v\n", constants.CheckMark.Render(), msg)
fmt.Printf(" %v\n", msg)
}

func Debug() {
Expand Down
2 changes: 1 addition & 1 deletion src/workingtree/workingtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func LoadWorkingTree(path string) WorkingTree {
fileExists := filesystem.FileExists(filepath.Join(path, WorkingTreeFile))

if !fileExists {
logger.Fatal[string]("Working tree file not found!")
logger.Result[string]("Working tree file not found!")
}

var tree WorkingTree
Expand Down

0 comments on commit 9ac9171

Please sign in to comment.