Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
This commit contains entire past history squashed to one commit.
I did that to avoid leaking anything sensitive when making
this repository public.
  • Loading branch information
wkozyra95 committed Apr 1, 2023
0 parents commit 77ce769
Show file tree
Hide file tree
Showing 275 changed files with 19,293 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dygma/*.json -diff linguist-generated=true
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
vendor
*.swo
*.swp
bin/mycli
bin/mycli-linux
bin/mycli-darwin

./secrets

*.spl
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Wojciech Kozyra

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lua_format=~/.cache/nvim/myconfig/lua_lsp/3rd/EmmyLuaCodeStyle/build/CodeFormat/CodeFormat
lua_config=./configs/nvim/lua.editorconfig

build:
CGO_ENABLED=0 go build -o bin/mycli ./mycli

unit-tests:
go test ./... -timeout 60m

e2e-tests:
go test -tags="integration" ./... -timeout 60m

watch:
modd

format:
golines --max-len=120 --base-formatter="gofumpt" -w .
find ./configs/nvim -iname '*.lua' | \
xargs -I {} $(lua_format) format -c $(lua_config) -f {} -ow

dev-e2e-test-env:
go run ./test/cmd
docker start -i system_setup_dev

dev-e2e-test-env-rebuild:
-docker stop system_setup_dev
-docker rm system_setup_dev
-docker rmi system_setup_dev_img
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# dotfiles


### Setup `mycli` inside Docker

```
curl -L -o mycli https://github.com/wkozyra95/dotfiles/releases/download/v0.0.0/mycli-linux && chmod +x mycli && ./mycli tool setup:environment:docker
```
246 changes: 246 additions & 0 deletions action/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
package action

import (
"fmt"
"strings"

"github.com/davecgh/go-spew/spew"
"github.com/wkozyra95/dotfiles/logger"
"github.com/wkozyra95/dotfiles/utils/prompt"
)

var log = logger.NamedLogger("action")

func printAction(depth int, text string) {
split := strings.Split(text, "\n")
for i := range split {
split[i] = fmt.Sprintf("%s%s", strings.Repeat(" ", depth), split[i])
}
fmt.Println(strings.Join(split, "\n"))
}

type actionCtx struct {
print bool
}

type Condition interface {
check(ctx actionCtx) (bool, error)
build() node
string() string
}

type Object interface {
run(ctx actionCtx, depth int) error
build() node
string() string
}

type node struct {
children []node
}

type List []Object

func (l List) build() node {
children := []node{}
for _, child := range l {
children = append(children, child.build())
}
return node{
children: children,
}
}

func (l List) run(ctx actionCtx, depth int) error {
for _, action := range l {
if ctx.print {
lines := strings.Split(action.string(), "\n")
if action.string() == "condition" {
// empty
} else if len(lines) == 1 {
printAction(depth, fmt.Sprintf(" - %s", lines[0]))
} else {
printAction(depth, fmt.Sprintf(" - %s", lines[0]))
printAction(depth+1, strings.Join(lines[1:], "\n"))
}
}
err := action.run(ctx, depth+1)
if err != nil {
return err
}
}
return nil
}

func (l List) string() string {
return ""
}

type Optional struct {
Object Object
}

func (o Optional) build() node {
return node{
children: []node{o.Object.build()},
}
}

func (o Optional) run(ctx actionCtx, depth int) error {
err := o.Object.run(ctx, depth+1)
if err != nil {
log.Error(err)
if !prompt.ConfirmPrompt("Install failed, do you want to continue?") {
return err
}
}
return nil
}

func (o Optional) string() string {
return ""
}

type WithCondition struct {
If Condition
Then Object
Else Object
}

func (a WithCondition) run(ctx actionCtx, depth int) error {
if ctx.print {
// This is hack, build action tree and print based on that
printAction(depth-1, fmt.Sprintf(" - If: %s", a.If.string()))
}
result, err := a.If.check(ctx)
if err != nil {
return err
}
if result {
if ctx.print {
printAction(depth, fmt.Sprintf("Then: %s", a.Then.string()))
}
return a.Then.run(ctx, depth+1)
} else if a.Else != nil {
if ctx.print {
printAction(depth, fmt.Sprintf("Else: %s", a.Else.string()))
}
return a.Else.run(ctx, depth+1)
} else {
if ctx.print {
printAction(depth, fmt.Sprintf("Else: do nothing"))
}
}
return nil
}

func (a WithCondition) build() node {
return node{
children: []node{
a.If.build(),
a.Then.build(),
a.Else.build(),
},
}
}

func (a WithCondition) string() string {
return "condition"
}

type SimpleActionBuilder[T any] struct {
CreateRun func(T) func() error
String func(T) string
}

type SimpleAction struct {
runImpl func() error
description string
}

func (s SimpleAction) run(ctx actionCtx, depth int) error {
return s.runImpl()
}

func (s SimpleAction) build() node {
return node{}
}

func (a SimpleAction) string() string {
return a.description
}

func (s SimpleActionBuilder[T]) Init() func(T) Object {
return func(t T) Object {
description := ""
if s.String != nil {
description = s.String(t)
} else {
description = strings.TrimRight(spew.Sdump(t), "\n ")
}
return SimpleAction{
runImpl: s.CreateRun(t),
description: description,
}
}
}

var Func = SimpleActionBuilder[func() error]{
CreateRun: func(fn func() error) func() error {
return func() error {
return fn()
}
},
}.Init()

type scope struct {
fn func() Object
}

func (s scope) run(ctx actionCtx, depth int) error {
return s.fn().run(ctx, depth)
}

func (s scope) build() node {
return s.fn().build()
}

func (a scope) string() string {
return ""
}

func Scope(fn func() Object) Object {
return scope{fn}
}

var nop = SimpleActionBuilder[struct{}]{
CreateRun: func(ignored struct{}) func() error {
return func() error {
return nil
}
},
}.Init()

func Nop() Object {
return nop(struct{}{})
}

var errAction = SimpleActionBuilder[error]{
CreateRun: func(err error) func() error {
return func() error {
return err
}
},
}.Init()

func Err(err error) Object {
return errAction(err)
}

func Run(o Object) error {
return o.run(actionCtx{print: true}, 0)
}

func RunSilent(o Object) error {
return o.run(actionCtx{print: false}, 0)
}

0 comments on commit 77ce769

Please sign in to comment.