Skip to content

Commit

Permalink
fixe app test and typo suggested by @MonsieurV
Browse files Browse the repository at this point in the history
  • Loading branch information
kpym committed Aug 21, 2021
1 parent 3d348f8 commit 6aadee8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ func GetParameters(params *builder.Parameters) error {
// the default writer is os.Stdout (color.Output)
params.Log = log.New(log.WithLevel(level), log.WithColor())

// Chack if the service support the requested options.
// normalise the service name
params.Service = strings.ToLower(params.Service)
// chack if the service support the requested options
if !stringIn(params.Service, "laton", "ytotech", "") {
return fmt.Errorf("Unknown %s service.", params.Service)
}
Expand Down Expand Up @@ -155,7 +157,7 @@ func GetParameters(params *builder.Parameters) error {
params.PipedMain = ((fi.Mode() & os.ModeCharDevice) == 0) && (fi.Mode()&os.ModeNamedPipe != 0)
params.Log.Debug("Piped input: %v, Stdin mode: %v.", params.PipedMain, fi.Mode())
}
// Get the patterns
// get the patterns
params.Patterns = append(pflag.Args(), params.Patterns...)
if len(params.Patterns) == 0 && params.Main == "" && !params.PipedMain {
return fmt.Errorf("Missing file to compile.")
Expand Down
3 changes: 2 additions & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"testing"

"github.com/kpym/lol/builder"
"github.com/kpym/lol/log"
)

func TestGetFiles(t *testing.T) {
// no Main, no Patterns
params := builder.Parameters{}
params := builder.Parameters{Log: log.New()}
files, err := GetFiles(params)

// Check for error
Expand Down
4 changes: 2 additions & 2 deletions builder/ytotech/ytotech.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func (y *ytotech) BuildPDF(req builder.Request) ([]byte, error) {
var comperr compilationError
err = json.Unmarshal(respBody, &comperr)
if err != nil {
return nil, fmt.Errorf("Laton compilation error (status code %d). The answer is not a valid json:\n%s\n", resp.StatusCode, respBody)
return nil, fmt.Errorf("YtoTech compilation error (status code %d). The answer is not a valid json:\n%s\n", resp.StatusCode, respBody)
}
return nil, fmt.Errorf("Laton compilation error (status code %d):\n%s\n", resp.StatusCode, comperr.Logs)
return nil, fmt.Errorf("YtoTech compilation error (status code %d):\n%s\n", resp.StatusCode, comperr.Logs)
}

// respBody contains the resulting pdf
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"
"time"

Expand Down Expand Up @@ -39,10 +40,13 @@ func main() {

// build the pdf
var compiler builder.Builder
if params.Service == "ytotech" {
switch params.Service {
case "ytotech":
compiler = ytotech.NewBuilder()
} else {
case "laton":
compiler = laton.NewBuilder()
default:
check(params.Log, fmt.Errorf("Unknown service %s", params.Service))
}
req := builder.Request{Parameters: params, Files: files}
params.Log.Info("Send request with the following parameters:\n%s", req.String())
Expand Down

0 comments on commit 6aadee8

Please sign in to comment.