Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: goreleaser

on:
pull_request:
push:

jobs:
goreleaser:
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
steps:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v3
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ bin
pkg
src/pkg


dist/
46 changes: 46 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
main: "./src/main.go"
binary: "exeiac"
archives:
- id: foo
name_template: >-
{{ .ProjectName }}_
{{ .Os }}_
{{ .Arch }}
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
nfpms:
-
package_name: exeiac
formats:
- deb
- archlinux
prerelease: alpha1
contents:
- src: ./src/completion/scripts/exeiac.fish
dst: /usr/share/fish/vendor_completions.d/
file_info:
mode: 0644
release:
github:
owner: half-shell
name: exeiac
mode: append

# modelines, feel free to remove those if you don't want/use them:
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
6 changes: 6 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
10 changes: 9 additions & 1 deletion src/actions/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ func PassthroughAction(
for i, b := range bricksToExecute {
report := ExecReport{Brick: b}

statusCode, err = b.Module.Exec(b, conf.Action, conf.OtherOptions, []string{})
// TODO(half-shell): Work around to avoid polluting conf's OtherOptions.
// Ideally, we would have a flexible way of providing a "non-interactive" flag
// to a module.
args := conf.OtherOptions
if !conf.Interactive {
args = append(args, "--non-interactive")
}

statusCode, err = b.Module.Exec(b, conf.Action, args, []string{})

if err != nil {
if actionNotImplementedError, isActionNotImplemented := err.(exinfra.ActionNotImplementedError); isActionNotImplemented {
Expand Down
11 changes: 9 additions & 2 deletions src/actions/lay.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@ func Lay(
return 3, err
}

// lay and manage error
exitStatus, err := b.Module.Exec(b, "lay", conf.OtherOptions, envs)
// TODO(half-shell): Work around to avoid polluting conf's OtherOptions.
// Ideally, we would have a flexible way of providing a "non-interactive" flag
// to a module.
args := conf.OtherOptions
if !conf.Interactive {
args = append(args, "--non-interactive")
}

exitStatus, err := b.Module.Exec(b, "lay", args, envs)
if err != nil {
skipFollowing = true
report.Error = err
Expand Down
11 changes: 9 additions & 2 deletions src/actions/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ func Plan(
return 3, err
}

// lay and manage error
exitStatus, err := b.Module.Exec(b, "plan", conf.OtherOptions, envs)
// TODO(half-shell): Work around to avoid polluting conf's OtherOptions.
// Ideally, we would have a flexible way of providing a "non-interactive" flag
// to a module.
args := conf.OtherOptions
if !conf.Interactive {
args = append(args, "--non-interactive")
}

exitStatus, err := b.Module.Exec(b, "plan", args, envs)
if err != nil {
report.Error = err
report.Status = TAG_ERROR
Expand Down
11 changes: 9 additions & 2 deletions src/actions/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ func Remove(
return 3, err
}

// lay and manage error
exitStatus, err := b.Module.Exec(b, "remove", conf.OtherOptions, envs)
// TODO(half-shell): Work around to avoid polluting conf's OtherOptions.
// Ideally, we would have a flexible way of providing a "non-interactive" flag
// to a module.
args := conf.OtherOptions
if !conf.Interactive {
args = append(args, "--non-interactive")
}

exitStatus, err := b.Module.Exec(b, "remove", args, envs)
if err != nil {
skipFollowing = true
report.Error = err
Expand Down
2 changes: 2 additions & 0 deletions src/arguments/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ type Arguments struct {
BricksNames []string
BricksSpecifiers []string
NonInteractive bool
Interactive bool
Format string
Modules map[string]string
OtherOptions []string
Rooms map[string]string
ConfigurationFile string
ShowUsage bool
ListBricks bool
}

func (a Arguments) String() string {
Expand Down
10 changes: 5 additions & 5 deletions src/arguments/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (a Configuration) String() string {
return sb.String()
}

func createConfiguration(confFilePath string) (configuration Configuration, err error) {
func CreateConfiguration(confFilePath string) (configuration Configuration, err error) {
file, err := os.ReadFile(confFilePath)
if err != nil {
return
Expand Down Expand Up @@ -113,13 +113,13 @@ func FromArguments(args Arguments) (configuration Configuration, err error) {
var conf Configuration

if args.ConfigurationFile != "" {
conf, err = createConfiguration(args.ConfigurationFile)
conf, err = CreateConfiguration(args.ConfigurationFile)
} else {
var configFilePath string

configFilePath, err = xdg.SearchConfigFile(CONFIG_FILE)
if err == nil {
conf, err = createConfiguration(configFilePath)
conf, err = CreateConfiguration(configFilePath)
}
}

Expand Down Expand Up @@ -164,10 +164,10 @@ func FromArguments(args Arguments) (configuration Configuration, err error) {
BricksSpecifiers: extools.Deduplicate(append(conf.BricksSpecifiers, args.BricksSpecifiers...)),
ConfigurationFile: args.ConfigurationFile,
Format: args.Format,
Interactive: !args.NonInteractive,
Interactive: (conf.Interactive && !args.NonInteractive) || args.Interactive,
Modules: modules,
Rooms: rooms,
OtherOptions: other_options,
OtherOptions: extools.Deduplicate(append(conf.OtherOptions, args.OtherOptions...)),
}

return
Expand Down
5 changes: 5 additions & 0 deletions src/arguments/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Includes: %v`, AvailableBricksSpecifiers))
flag.BoolVarP(&Args.NonInteractive, "non-interactive", "I", false,
"Allows for exeiac to run without user input")

flag.BoolVarP(&Args.Interactive, "interactive", "i", false,
"Forces exeiac to wait for user input when needed. Overwrites the --non-interactive (-I) flag.")

flag.StringVarP(&Args.Format, "format", "f", "all",
fmt.Sprintf(`Define the format of the output. It matches the brick's specifiers values
Includes: %v`, AvailableBricksSpecifiers))
Expand All @@ -45,6 +48,8 @@ to it. Flag with arguments need to be enclosed in double quotes

flag.BoolVarP(&Args.ShowUsage, "help", "h", false, "Show exeiac's help")

flag.BoolVarP(&Args.ListBricks, "list-bricks", "l", false, "List all the bricks from all rooms")

flag.Usage = func() {
fmt.Println("Usage: exeiac ACTION (BRICK_PATH|BRICK_NAME) [OPTION...]")
fmt.Println()
Expand Down
21 changes: 21 additions & 0 deletions src/completion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Exeiac completion
A small package to provide an auto-completion to different shells (bash, zsh, fish).

It justs references all brick's in a configuration file's "Rooms" section, and return them.

## Setup
*Instructions on how to build the binary used for brick's auto-completion.*
```bash
$ go install completion
```

## Bash

## Zsh

## Fish
To enable the fish auto-completion, you can just copy the `./scripts/exeiac.fish` file to `~/.config/fish/completions/exeiac.fish`.
```fish
$ cp ./scripts/exeiac.fish ~/.config/fish/completions/exeiac.fish
```
You should have completion enabled once
22 changes: 22 additions & 0 deletions src/completion/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package completion

import (
"fmt"
"os"
exargs "src/exeiac/arguments"
"src/exeiac/infra"
)

func ListBricks(configuration exargs.Configuration) {
var bricks infra.Bricks
for roomName, roomPath := range configuration.Rooms {
bs, err := infra.GetBricks(roomName, roomPath)
if err == nil {
bricks = append(bricks, bs...)
}
}

for _, b := range bricks {
fmt.Fprintln(os.Stdout, b.Name)
}
}
11 changes: 11 additions & 0 deletions src/completion/scripts/exeiac.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set -l actions init plan lay remove help validate_code show clean

# Prevent file auto completion
complete -c exeiac -f

# Auto completion for sub-commands (actions)
complete -c exeiac -n "not __fish_seen_subcommand_from $commands" -a "$actions"

# Auto completion for bricks
# TODO(half-shell): Replace with a GOPATH or a go command
complete -c exeiac -n "__fish_seen_subcommand_from $actions" -a "(exeiac -l)"
29 changes: 25 additions & 4 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
exaction "src/exeiac/actions"
exargs "src/exeiac/arguments"
excompletion "src/exeiac/completion"
exinfra "src/exeiac/infra"

flag "github.com/spf13/pflag"
Expand All @@ -26,11 +27,18 @@ func main() {

// The only remaining arguments are not flags. They match the action and the brickNames
nonFlagArgs := flag.Args()
if len(nonFlagArgs) == 0 {
fmt.Fprintln(os.Stderr, "argument missing: you need at least to specify one action")
os.Exit(2)

// NOTE(half-shell): We need the configuration created to list all bricks so we bypass
// the check made on the action and bricks if the "list bricks" flag is provided.
if !exargs.Args.ListBricks {
if len(nonFlagArgs) == 0 {
fmt.Fprintln(os.Stderr, "argument missing: you need at least to specify one action")

os.Exit(2)
}

exargs.Args.Action, exargs.Args.BricksNames = nonFlagArgs[0], nonFlagArgs[1:]
}
exargs.Args.Action, exargs.Args.BricksNames = nonFlagArgs[0], nonFlagArgs[1:]

configuration, err := exargs.FromArguments(exargs.Args)
if err != nil {
Expand All @@ -39,6 +47,12 @@ func main() {
os.Exit(2)
}

if exargs.Args.ListBricks {
excompletion.ListBricks(configuration)

os.Exit(0)
}

// build infra representation
infra, err := exinfra.CreateInfra(configuration)
if err != nil {
Expand Down Expand Up @@ -75,6 +89,13 @@ func main() {
os.Exit(1)
}

if len(bricksToExecute) == 0 {
err = fmt.Errorf("No bricks was found to need actions. Check the provided brick(s) and selectors (if any).")
fmt.Fprintln(os.Stderr, err)

os.Exit(3)
}

// executeAction
// if exargs.Args.action is in the list do that else use otherAction
if behaviour, ok := exaction.BehaviourMap[configuration.Action]; ok {
Expand Down