Skip to content

Commit

Permalink
Simplify cli merging encode and analyse into single subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
jurisevo committed Nov 28, 2022
1 parent e8dfc38 commit 325c5f4
Show file tree
Hide file tree
Showing 14 changed files with 558 additions and 771 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- if: steps.cache-ffmpeg.outputs.cache-hit != 'true'
name: Install static ffmpeg
run: |
curl --connect-timeout 10 -Lv -o ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
curl --connect-timeout 10 -Lv -o ffmpeg.tar.xz https://web.archive.org/web/20220502225332/https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
echo "07149022696e10e528f48f402c3b8570 ffmpeg.tar.xz" | md5sum --check -
mkdir -p "$FFMPEG_DEST_DIR"
tar -C "$FFMPEG_DEST_DIR" -xf ffmpeg.tar.xz --strip-components=1
Expand Down
5 changes: 1 addition & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@ linters:
disable-all: true
enable:
# Default list
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
# Additional
- dupl
- errname
- misspell
- gocritic
- godot
- gofumpt
- goimports
- goheader
- gosec
220 changes: 0 additions & 220 deletions analyse.go

This file was deleted.

59 changes: 59 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ package main

import (
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"log"
"os"
"strings"

"github.com/evolution-gaming/ease/internal/encoding"
"github.com/evolution-gaming/ease/internal/logging"
Expand Down Expand Up @@ -124,3 +126,60 @@ func extractSourceData(r *report) map[string]sourceData {
}
return s
}

// unrollResultErrors helper to unroll all errors from RunResults into a string.
func unrollResultErrors(results []encoding.RunResult) string {
sb := strings.Builder{}
for i := range results {
rr := &results[i]
if len(rr.Errors) != 0 {
for _, e := range rr.Errors {
sb.WriteString(fmt.Sprintf("%s:\n\t%s\n", rr.Name, e.Error()))
}
}
}
return sb.String()
}

// createPlanConfig creates a PlanConfig instance from JSON configuration.
func createPlanConfig(cfgFile string) (pc encoding.PlanConfig, err error) {
fd, err := os.Open(cfgFile)
if err != nil {
return pc, fmt.Errorf("cannot open conf file: %w", err)
}
defer fd.Close()

jdoc, err := io.ReadAll(fd)
if err != nil {
return pc, fmt.Errorf("cannot read data from conf file: %w", err)
}

pc, err = encoding.NewPlanConfigFromJSON(jdoc)
if err != nil {
return pc, fmt.Errorf("cannot create PlanConfig: %w", err)
}

if ok, err := pc.IsValid(); !ok {
ev := &encoding.PlanConfigError{}
if errors.As(err, &ev) {
logging.Debugf(
"PlanConfig validation failures:\n%s",
strings.Join(ev.Reasons(), "\n"))
}
return pc, fmt.Errorf("PlanConfig not valid: %w", err)
}

return pc, nil
}

// isNonEmptyDir will check if given directory is non-empty.
func isNonEmptyDir(path string) bool {
fs, err := os.Open(path)
if err != nil {
return false
}
defer fs.Close()

n, _ := fs.Readdirnames(1)
return len(n) == 1
}
Loading

0 comments on commit 325c5f4

Please sign in to comment.