Skip to content

Commit

Permalink
feat: change workflow, fix ids, change logger, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
costaluu committed Sep 20, 2024
1 parent a4fddb6 commit ef6aed1
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 70 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ jobs:
# Zip only the linux, macos, and windows folders without the full path
cd $OUTPUT_DIR
zip -r flag-windows.zip windows
zip -r flag-linux.zip linux
zip -r flag-macos.zip macos
zip -r flag-windows.zip windows/$BINARY_NAME.exe
zip -r flag-linux.zip linux/$BINARY_NAME
zip -r flag-macos.zip macos/$BINARY_NAME
- name: List contents of bin directory
run: |
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Flag

**Flag** is a branch-level feature flag manager designed to enable feature toggling at the file level. With deep integration into Git, Flag automatically adapts files in your repository based on which features are turned on or off.
**Flag** is a configuration-based feature flag manager. Works on top of Git, Flag automatically adapts files in your repository based on which features are turned on or off.

> [!WARNING]
> Disclaimer: This system is currently in Beta. Use with caution in production environments.
> Disclaimer: Use with caution in production environments.
## Table of Contents

Expand Down
5 changes: 5 additions & 0 deletions src/bubbletea/components/fileiterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func (m IteratorModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.index >= len(m.paths)-1 {
// Everything's been installed. We're done!
m.done = true

fmt.Println("finalizou terminou")
return m, tea.Sequence(
tea.Printf("%s %s", constants.CheckMark.Render(), path.Path), // print the last success message
tea.Quit, // exit the program
Expand Down Expand Up @@ -112,8 +114,11 @@ func FileIterator(list []types.FilePathCategory, run func (parameter types.FileP

model := newIteratorModel(list, runner)

fmt.Println("file operator comecou")

if _, err := tea.NewProgram(model).Run(); err != nil {
logger.Fatal[error](err)
}

fmt.Println("file operator terminou")
}
3 changes: 2 additions & 1 deletion src/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import "github.com/charmbracelet/lipgloss"
var (
APP_NAME = "flag"
COMMAND = "flag"
VERSION = "v0.0.1"
VERSION = "v0.0.2"
MIN_FEATURE_CHARACTERS = 5
ID_LENGTH = 25
)

var (
Expand Down
9 changes: 8 additions & 1 deletion src/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/costaluu/flag/table"
"github.com/costaluu/flag/types"
"github.com/costaluu/flag/utils"
gonanoid "github.com/matoous/go-nanoid/v2"
)

func ExtractMatchDataFromFile(path string) []types.Match {
Expand Down Expand Up @@ -43,7 +44,13 @@ func ExtractMatchDataFromFile(path string) []types.Match {
foundId = true
id = match[3]
} else {
id = utils.GenerateId()
nanoId, err := gonanoid.New(16)

if err != nil {
logger.Fatal[error](err)
}

id = utils.GenerateId(path, feature, nanoId)
}

var featureContent string
Expand Down
54 changes: 30 additions & 24 deletions src/core/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,11 @@ func CommitBase(path string, skipForm bool) {
}

func CommitNewFeature(path string, name string, skipForm bool, finalMessage bool) {
timestamp := utils.GenerateCurrentTimeStampString()

var rootDir string = git.GetRepositoryRoot()
hashedPath := utils.HashFilePath(path)
features := GetCommitFeaturesFromPath(hashedPath)

var featureExists bool = false
var hasOtherFeaturesTurnedOn bool
var featureIdsTurnedOn []string = []string{}
var featureNamesTurnedOn []string = []string{}
Expand All @@ -263,12 +262,18 @@ func CommitNewFeature(path string, name string, skipForm bool, finalMessage bool
if feature.State == constants.STATE_ON {
if feature.Name != name {
hasOtherFeaturesTurnedOn = true
} else {
featureExists = true
}

featureIdsTurnedOn = append(featureIdsTurnedOn, feature.Id)
featureNamesTurnedOn = append(featureNamesTurnedOn, feature.Name)
}
}

if featureExists {
logger.Result[string](fmt.Sprintf("feature %s already exists"))
}

if !skipForm && hasOtherFeaturesTurnedOn {
var warningMessage string = fmt.Sprintf("Warning\n\nA total of %d feature(s) are currently turned on and they also change %s\n\n", len(features), path)
Expand All @@ -289,7 +294,7 @@ func CommitNewFeature(path string, name string, skipForm bool, finalMessage bool
}

var newFeature types.CommitFeature
var id string = utils.GenerateId()
var id string = utils.GenerateId(path, name)

featureIdsTurnedOn = append(featureIdsTurnedOn, id)

Expand All @@ -302,13 +307,14 @@ func CommitNewFeature(path string, name string, skipForm bool, finalMessage bool
featureNamesTurnedOn = append(featureNamesTurnedOn, name)
newRecordCheckSum := filesystem.FileGenerateCheckSum(filepath.Join(rootDir, path))

workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), []string{newFeature.Id}, timestamp + newRecordCheckSum)
filesystem.FileCopy(filepath.Join(rootDir, path), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, timestamp + newRecordCheckSum))
workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), []string{newFeature.Id}, strings.Join([]string{newFeature.Id, newRecordCheckSum}, "+"))
filesystem.FileCopy(filepath.Join(rootDir, path), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, strings.Join([]string{newFeature.Id, newRecordCheckSum}, "+")))

if hasOtherFeaturesTurnedOn {
timestamp = utils.GenerateCurrentTimeStampString()
workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), featureIdsTurnedOn, timestamp + newRecordCheckSum)
filesystem.FileCopy(filepath.Join(rootDir, path), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, timestamp + newRecordCheckSum))
newVersionChecksum := strings.Join(append(featureIdsTurnedOn, newRecordCheckSum), "+")

workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), featureIdsTurnedOn, newVersionChecksum)
filesystem.FileCopy(filepath.Join(rootDir, path), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, newVersionChecksum))
}

filesystem.FileWriteJSONToFile(filepath.Join(rootDir, ".features", "commits", hashedPath, fmt.Sprintf("%s.feature", newFeature.Id)), newFeature)
Expand Down Expand Up @@ -346,10 +352,10 @@ func CommitSaveToCurrentState(path string) {
filesystem.RemoveFile(filepath.Join(rootDir, ".features", "commits", hashedPath, constants.WorkingTreeDirectory, checksum))

newRecordCheckSum := filesystem.FileGenerateCheckSum(filepath.Join(rootDir, path))
timestamp := utils.GenerateCurrentTimeStampString()
newVersionChecksum := strings.Join(append(currentFeaturesIdsTurnedOn, newRecordCheckSum), "+")

workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), currentFeaturesIdsTurnedOn, timestamp + newRecordCheckSum)
filesystem.FileCopy(filepath.Join(rootDir, path), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, timestamp + newRecordCheckSum))
workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), currentFeaturesIdsTurnedOn, newVersionChecksum)
filesystem.FileCopy(filepath.Join(rootDir, path), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, newVersionChecksum))

BuildBaseForFile(path)
}
Expand Down Expand Up @@ -437,10 +443,10 @@ func CommitSave(path string, finalMessage bool) {
filesystem.RemoveFile(filepath.Join(rootDir, ".features", "commits", hashedPath, constants.WorkingTreeDirectory, checksum))

newRecordCheckSum := filesystem.FileGenerateCheckSum(filepath.Join(rootDir, path))
timestamp := utils.GenerateCurrentTimeStampString()
newVersionChecksum := strings.Join(append(workingtree.StringToStringSlice(selected.ItemValue), newRecordCheckSum), "+")

workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), workingtree.StringToStringSlice(selected.ItemValue), timestamp + newRecordCheckSum)
filesystem.FileCopy(filepath.Join(rootDir, path), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, timestamp + newRecordCheckSum))
workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), workingtree.StringToStringSlice(selected.ItemValue), newVersionChecksum)
filesystem.FileCopy(filepath.Join(rootDir, path), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, newVersionChecksum))

BuildBaseForFile(path)

Expand Down Expand Up @@ -653,11 +659,11 @@ func BuildBaseForFile(path string) {

newCheckSum := filesystem.FileGenerateCheckSum(filepath.Join(rootDir, ".features", "merge-tmp"))

timestamp := utils.GenerateCurrentTimeStampString()
newVersionChecksum := strings.Join(append(nearPrefix, newCheckSum), "+")

workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), nearPrefix, timestamp + newCheckSum)
workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), nearPrefix, newVersionChecksum)

filesystem.FileCopy(filepath.Join(rootDir, ".features", "merge-tmp"), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, timestamp + newCheckSum))
filesystem.FileCopy(filepath.Join(rootDir, ".features", "merge-tmp"), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, newVersionChecksum))
}

filesystem.FileCopy(filepath.Join(rootDir, ".features", "merge-tmp"), filepath.Join(rootDir, path))
Expand Down Expand Up @@ -781,12 +787,12 @@ func RebaseFile(path string, finalMessage bool) {
)

newCheckSum := filesystem.FileGenerateCheckSum(filepath.Join(rootDir, ".features", "merge-tmp"))
timestamp := utils.GenerateCurrentTimeStampString()
newVersionChecksum := strings.Join(append(featureIds, newCheckSum), "+")

filesystem.RemoveFile(filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, checksum))

workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), featureIds, timestamp + newCheckSum)
filesystem.FileCopy(filepath.Join(rootDir, ".features", "merge-tmp"), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, timestamp + newCheckSum))
workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), featureIds, newVersionChecksum)
filesystem.FileCopy(filepath.Join(rootDir, ".features", "merge-tmp"), filepath.Join(rootDir, ".features", "commits", hashedPath, workingtree.WorkingTreeDirectory, newVersionChecksum))
}

filesystem.RemoveFile(filepath.Join(rootDir, ".features", "merge-tmp"))
Expand Down Expand Up @@ -1159,11 +1165,11 @@ func CommitPromoteOnPath(fullPath string, parsedPath string, featureNamesToPromo
workingtree.Remove(filepath.Join(rootDir, ".features", "commits", hashedPath), ids)
filesystem.RemoveFile(filepath.Join(rootDir, ".features", "commits", hashedPath, constants.WorkingTreeDirectory, checksum))

newChecksum := filesystem.FileGenerateCheckSum(filepath.Join(rootDir, ".features", "merge-tmp"))
timestamp := utils.GenerateCurrentTimeStampString()
newCheckSum := filesystem.FileGenerateCheckSum(filepath.Join(rootDir, ".features", "merge-tmp"))
newVersionChecksum := strings.Join(append(idsSlice, newCheckSum), "+")

workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), idsSlice, timestamp + newChecksum)
filesystem.FileCopy(filepath.Join(rootDir, ".features", "merge-tmp"), filepath.Join(rootDir, ".features", "commits", hashedPath, constants.WorkingTreeDirectory, timestamp + newChecksum))
workingtree.Add(filepath.Join(rootDir, ".features", "commits", hashedPath), idsSlice, newVersionChecksum)
filesystem.FileCopy(filepath.Join(rootDir, ".features", "merge-tmp"), filepath.Join(rootDir, ".features", "commits", hashedPath, constants.WorkingTreeDirectory, newVersionChecksum))
}

// Change base to the feature/state promoted
Expand Down
4 changes: 4 additions & 0 deletions src/core/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,9 @@ func Sync() {
}
}

fmt.Println("sync comecou")

components.FileIterator(arrayFile, runner)

fmt.Println("sync terminou")
}
14 changes: 13 additions & 1 deletion src/core/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ func CreateNewWorkspace() {
Start: "<!-- ",
End: " -->",
},
".html": {
Start: "<!-- ",
End: " -->",
},
".cc": {
Start: "// ",
End: " //",
},
".cpp": {
Start: "// ",
End: " //",
},
".go": {
Start: "// ",
End: " //",
Expand All @@ -63,7 +75,7 @@ func CreateNewWorkspace() {

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

logger.Success[string]("folder .features created!")
logger.Success[string]("folder .features created")
}

func WorkspaceReport() {
Expand Down
59 changes: 52 additions & 7 deletions src/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,79 @@ import (
"fmt"
"os"
"runtime/debug"

"github.com/charmbracelet/lipgloss"
)

var infoStyle =
lipgloss.
NewStyle().
SetString("info").
Foreground(lipgloss.Color("#3775c4")).
Underline(true).
Bold(true)

var errorStyle =
lipgloss.
NewStyle().
SetString("error").
Foreground(lipgloss.Color("#e25822")).
Underline(true).
Bold(true)

var warningStyle =
lipgloss.
NewStyle().
SetString("warning").
Foreground(lipgloss.Color("#f2f27a")).
Underline(true).
Bold(true)

var sucessStyle =
lipgloss.
NewStyle().
SetString("success").
Foreground(lipgloss.Color("#14b37d")).
Underline(true).
Bold(true)

var chevronRight = renderDefault[string]("›")

func renderDefault[T any](msg T) string {
var defaultStyle =
lipgloss.
NewStyle().
SetString(fmt.Sprintf("%s", msg)).
Foreground(lipgloss.Color("242"))

return defaultStyle.Render()
}

func Info[T any](msg T) {
fmt.Printf("🔎 %v\n", msg)
fmt.Printf("%s 🔎 %s %v\n", chevronRight, infoStyle.Render(), renderDefault(msg))
}

func Result[T any](msg T) {
fmt.Printf("🔎 %v\n", msg)
fmt.Printf("%s 🔎 %s %v\n", chevronRight, infoStyle.Render(), renderDefault(msg))
os.Exit(0)
}

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

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

func Warning[T any](msg T) {
fmt.Printf("🚨 %v\n", msg)
fmt.Printf("%s 🚧 %s %v\n", chevronRight, warningStyle.Render(), renderDefault(msg))
}

func Success[T any](msg T) {
fmt.Printf("✅ %v\n", msg)
fmt.Printf("%s ✅ %s %v\n", chevronRight, sucessStyle.Render(), renderDefault(msg))
}

func Debug() {
Expand Down
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/costaluu/flag/constants"
"github.com/urfave/cli/v2"
)

func main() {
app := &cli.App{
Name: constants.APP_NAME,
Expand Down
2 changes: 1 addition & 1 deletion src/resolver/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (flr *FileLineReader) ReadLine(lineNumber int) (string, error) {
resultLine := scanner.Text()

if strings.HasPrefix(resultLine, "<<<<<<<") || strings.HasPrefix(resultLine, ">>>>>>>") {
return "", fmt.Errorf("Found another conflict!")
return "", fmt.Errorf("Found another conflict")
}

return resultLine, nil
Expand Down
6 changes: 0 additions & 6 deletions src/types/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ type BlockFeature struct {
SwapContent string `json:"swapContent"`
}

type LinkFeature struct {
Name string `json:"name"`
State string `json:"state"`
Synced bool `json:"synced"`
}

type CommitFeature struct {
Id string `json:"id"`
Name string `json:"name"`
Expand Down
Loading

0 comments on commit ef6aed1

Please sign in to comment.