support single input file
This commit is contained in:
parent
3727173f31
commit
20ecd634cc
3 changed files with 17 additions and 18 deletions
|
|
@ -18,7 +18,7 @@
|
|||
.Nm d2
|
||||
.Ar play Ar file.d2
|
||||
.Nm d2
|
||||
.Ar validate Ar file.d2 ...
|
||||
.Ar validate Ar file.d2
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
compiles and renders
|
||||
|
|
@ -164,8 +164,8 @@ Lists available themes
|
|||
Format all passed files
|
||||
.It Ar play Ar file.d2
|
||||
Opens the file in playground, an online web viewer (https://play.d2lang.com)
|
||||
.It Ar validate Ar file.d2 ...
|
||||
Validate all input files
|
||||
.It Ar validate Ar file.d2
|
||||
Validate all input file
|
||||
.El
|
||||
.Sh ENVIRONMENT VARIABLES
|
||||
Many flags can also be set with environment variables.
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ Usage:
|
|||
%[1]s layout [name]
|
||||
%[1]s fmt file.d2 ...
|
||||
%[1]s play [--theme=0] [--sketch] file.d2
|
||||
%[1]s validate file.d2 ...
|
||||
%[1]s validate file.d2
|
||||
|
||||
%[1]s compiles and renders file.d2 to file.svg | file.png
|
||||
It defaults to file.svg if an output path is not provided.
|
||||
|
|
@ -41,7 +41,7 @@ Subcommands:
|
|||
%[1]s themes - Lists available themes
|
||||
%[1]s fmt file.d2 ... - Format passed files
|
||||
%[1]s play file.d2 - Opens the file in playground, an online web viewer (https://play.d2lang.com)
|
||||
%[1]s validate file.d2 ... - Validate input files
|
||||
%[1]s validate file.d2 - Validate input file
|
||||
|
||||
See more docs and the source code at https://oss.terrastruct.com/d2.
|
||||
Hosted icons at https://icons.terrastruct.com.
|
||||
|
|
|
|||
|
|
@ -13,23 +13,22 @@ func validateCmd(ctx context.Context, ms *xmain.State) (err error) {
|
|||
|
||||
ms.Opts = xmain.NewOpts(ms.Env, ms.Opts.Flags.Args()[1:])
|
||||
if len(ms.Opts.Args) == 0 {
|
||||
return xmain.UsageErrorf("validate must be passed at least one file to be validated")
|
||||
return xmain.UsageErrorf("validate must be passed an input file to be validated")
|
||||
}
|
||||
|
||||
for _, inputPath := range ms.Opts.Args {
|
||||
if inputPath != "-" {
|
||||
inputPath = ms.AbsPath(inputPath)
|
||||
}
|
||||
inputPath := ms.Opts.Args[0]
|
||||
if inputPath != "-" {
|
||||
inputPath = ms.AbsPath(inputPath)
|
||||
}
|
||||
|
||||
input, err := ms.ReadPath(inputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
input, err := ms.ReadPath(inputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = d2lib.Parse(ctx, string(input), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = d2lib.Parse(ctx, string(input), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue