Skip to content

Commit

Permalink
update goreleaser for arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhaley committed Feb 17, 2022
1 parent f914011 commit 545fd23
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ builds:
- windows
goarch:
- amd64
- arm64
ldflags:
- -s -w -X main.Version={{.Version}}

Expand Down
99 changes: 99 additions & 0 deletions ssmsh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package main

import (
"flag"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/abiosoft/ishell"
"github.com/bwhaley/ssmsh/commands"
"github.com/bwhaley/ssmsh/config"
"github.com/bwhaley/ssmsh/parameterstore"
"github.com/mattn/go-shellwords"
)

var Version string

func main() {
cfgFile := flag.String("config", "", "Load configuration from the specified file")
file := flag.String("file", "", "Read commands from file (use - for stdin)")
version := flag.Bool("version", false, "Display the current version")
flag.Parse()

if *version {
fmt.Println("Version", Version)
os.Exit(0)
}

cfg, err := config.ReadConfig(*cfgFile)
if err != nil {
fmt.Printf("Error reading configuration file %s: %s\n", *cfgFile, err)
os.Exit(1)
}

shell := ishell.New()
var ps parameterstore.ParameterStore
ps.SetDefaults(cfg)
err = ps.NewParameterStore(true)
if err != nil {
shell.Println("Error initializing session. Is your authentication correct?", err)
os.Exit(1)
}
commands.Init(shell, &ps, &cfg)

if *file == "-" {
processStdin(shell)
} else if *file != "" {
processFile(shell, *file)
} else if len(flag.Args()) > 1 {
err := shell.Process(flag.Args()...)
if err != nil {
shell.Println("Error executing shell process:", err)
shell.Println("This might be a bug. Please open an issue at github.com/bwhaley/ssmsh.\n")
os.Exit(1)
}
} else {
shell.Run()
shell.Close()
}
}

func processStdin(shell *ishell.Shell) {
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
shell.Println("Error reading from stdin:", err)
os.Exit(1)
}
processData(shell, string(data))
}

func processFile(shell *ishell.Shell, fn string) {
data, err := ioutil.ReadFile(fn)
if err != nil {
shell.Println("Error reading from file:", err)
}
processData(shell, string(data))
}

func processData(shell *ishell.Shell, data string) {
lines := strings.Split(data, "\n")
for _, line := range lines {
if line == "" || string(line[0]) == "#" {
continue
}
args, err := shellwords.Parse(line)
if err != nil {
msg := fmt.Errorf("Error parsing %s: %v", line, err)
shell.Println(msg)
os.Exit(1)
}
err = shell.Process(args...)
if err != nil {
msg := fmt.Errorf("Error executing %s: %v", line, err)
shell.Println(msg)
os.Exit(1)
}
}
}

0 comments on commit 545fd23

Please sign in to comment.