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
|
.Nm d2
|
||||||
.Ar play Ar file.d2
|
.Ar play Ar file.d2
|
||||||
.Nm d2
|
.Nm d2
|
||||||
.Ar validate Ar file.d2 ...
|
.Ar validate Ar file.d2
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
compiles and renders
|
compiles and renders
|
||||||
|
|
@ -164,8 +164,8 @@ Lists available themes
|
||||||
Format all passed files
|
Format all passed files
|
||||||
.It Ar play Ar file.d2
|
.It Ar play Ar file.d2
|
||||||
Opens the file in playground, an online web viewer (https://play.d2lang.com)
|
Opens the file in playground, an online web viewer (https://play.d2lang.com)
|
||||||
.It Ar validate Ar file.d2 ...
|
.It Ar validate Ar file.d2
|
||||||
Validate all input files
|
Validate all input file
|
||||||
.El
|
.El
|
||||||
.Sh ENVIRONMENT VARIABLES
|
.Sh ENVIRONMENT VARIABLES
|
||||||
Many flags can also be set with environment variables.
|
Many flags can also be set with environment variables.
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ Usage:
|
||||||
%[1]s layout [name]
|
%[1]s layout [name]
|
||||||
%[1]s fmt file.d2 ...
|
%[1]s fmt file.d2 ...
|
||||||
%[1]s play [--theme=0] [--sketch] 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
|
%[1]s compiles and renders file.d2 to file.svg | file.png
|
||||||
It defaults to file.svg if an output path is not provided.
|
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 themes - Lists available themes
|
||||||
%[1]s fmt file.d2 ... - Format passed files
|
%[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 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.
|
See more docs and the source code at https://oss.terrastruct.com/d2.
|
||||||
Hosted icons at https://icons.terrastruct.com.
|
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:])
|
ms.Opts = xmain.NewOpts(ms.Env, ms.Opts.Flags.Args()[1:])
|
||||||
if len(ms.Opts.Args) == 0 {
|
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 {
|
inputPath := ms.Opts.Args[0]
|
||||||
if inputPath != "-" {
|
if inputPath != "-" {
|
||||||
inputPath = ms.AbsPath(inputPath)
|
inputPath = ms.AbsPath(inputPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
input, err := ms.ReadPath(inputPath)
|
input, err := ms.ReadPath(inputPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = d2lib.Parse(ctx, string(input), nil)
|
_, err = d2lib.Parse(ctx, string(input), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue