diff options
| -rw-r--r-- | cmd/lulu/cd.go | 22 | ||||
| -rw-r--r-- | cmd/lulu/cli.go | 7 | ||||
| -rw-r--r-- | cmd/lulu/vc.go | 41 |
3 files changed, 67 insertions, 3 deletions
diff --git a/cmd/lulu/cd.go b/cmd/lulu/cd.go new file mode 100644 index 0000000..aaefaa0 --- /dev/null +++ b/cmd/lulu/cd.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + + "git.samanthony.xyz/lulu" +) + +type CoverDimensionsCmd struct { + Mfg lulu.PkgId `arg help:"${mfg_help}"` + NPages uint `arg name:"npages" help:"Number of interior pages"` + Unit lulu.Unit `short:"u" default:"pt" help:"${unit_help}"` +} + +func (cmd CoverDimensionsCmd) Run(clnt *lulu.Client) error { + dims, err := clnt.CoverDimensions(cmd.Mfg, cmd.NPages, cmd.Unit) + if err != nil { + return err + } + fmt.Println(dims) + return nil +} diff --git a/cmd/lulu/cli.go b/cmd/lulu/cli.go index 2cc0798..b791d1f 100644 --- a/cmd/lulu/cli.go +++ b/cmd/lulu/cli.go @@ -12,6 +12,7 @@ import ( var helpVars = kong.Vars{ "mfg_help": "Manufacturing settings. Run 'lulu list mfg' for valid values", "ship_level_help": "Shipping speed. Run 'lulu list ship' for valid values", + "unit_help": fmt.Sprintf("Unit of measurement: %s", lulu.UnitValues()), "default_timeout": defaultTimeout.String(), } @@ -19,9 +20,9 @@ type CLI struct { Globals ValidateInterior ValidateInteriorCmd `cmd name:"vi" help:"Validate an interior file"` - //TODO ValidateCover ValidateCoverCmd `cmd name:"vc" help:"Validate a cover file"` - //TODO CoverDimensions CoverDimensionsCmd `cmd name:"cd" help:"Calculate the required dimensions of the cover"` - Cost CostCmd `cmd help:"Calculate the cost of a print job"` + ValidateCover ValidateCoverCmd `cmd name:"vc" help:"Validate a cover file"` + CoverDimensions CoverDimensionsCmd `cmd name:"cd" help:"Calculate the required dimensions of the cover"` + Cost CostCmd `cmd help:"Calculate the cost of a print job"` List ListCmd `cmd help:"Print a list of valid argument values"` } diff --git a/cmd/lulu/vc.go b/cmd/lulu/vc.go new file mode 100644 index 0000000..4801af9 --- /dev/null +++ b/cmd/lulu/vc.go @@ -0,0 +1,41 @@ +package main + +import ( + "context" + "fmt" + "net/url" + "time" + + "github.com/alecthomas/kong" + + "git.samanthony.xyz/lulu" +) + +type ValidateCoverCmd struct { + Url *url.URL `arg help:"Location of cover file"` + Mfg lulu.PkgId `arg help:"${mfg_help}"` + NPages uint `arg name:"npages" help:"Number of interior pages"` + Timeout time.Duration `short:"t" default:"${default_timeout}"` +} + +func (cmd ValidateCoverCmd) Run(cli *kong.Kong, clnt *lulu.Client) error { + ctx, cancel := context.WithTimeout(clnt.Context(), cmd.Timeout) + defer cancel() + val, err := clnt.ValidateCover(ctx, cmd.Url.String(), cmd.Mfg, cmd.NPages) + if err != nil { + return err + } + fmt.Println("status:", val.Status) + fmt.Println("id:", val.Id) + if len(val.Errors) > 0 { + for _, err := range val.Errors { + cli.Errorf("%v\n", err) + } + return fmt.Errorf("response contains errors") + } + wantStatus := lulu.CoverStatusNormalized + if val.Status != wantStatus { + return fmt.Errorf("bad status %q; expected %q\n", val.Status, wantStatus) + } + return nil +} |