siyuan-note/siyuan · error

--name is required

Error message

--name is required

What it means

`siyuan template save-as` validates `--name` (the template file name to create) after `--id`. When the name flag is missing or empty the command returns this error, since a template must be stored under a concrete .md file name.

Solutions

  1. Add a name: `siyuan template save-as --id <id> --name mytpl`
  2. Pick a name that does not include the .md extension (it is appended on save)
  3. Quote the value to avoid shell splitting

Example fix

// before
siyuan template save-as --id 20240101120000-abcdefg
// after
siyuan template save-as --id 20240101120000-abcdefg --name mytpl
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "$NAME" ]; then echo "--name is required" >&2; exit 2; fi
siyuan template save-as --id "$DOC_ID" --name "$NAME"

Try / catch

if ! siyuan template save-as --id "$ID" --name "$NAME"; then
  echo "save-as failed; provide --name or --overwrite if it exists" >&2
fi

Prevention

When it happens

Trigger: Running `siyuan template save-as --id <id>` without `--name`, or with `--name ""`.

Common situations: Providing only the document id; empty name variable in scripts; assuming the command derives a default name from the document title (it does not).

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/84ea240f7016d930. Report an issue: GitHub.

Appendix: source

Thrown at kernel/cli/cmd/template.go:152

		if err != nil {
			return err
		}
		fmt.Print(dom)
		return nil
	},
}

var templateSaveAsCmd = &cobra.Command{
	Use:   "save-as --id <id> --name <name>",
	Short: "Save a document as a template",
	RunE: func(cmd *cobra.Command, args []string) error {
		id, _ := cmd.Flags().GetString("id")
		name, _ := cmd.Flags().GetString("name")
		if id == "" {
			return fmt.Errorf("--id is required")
		}
		if name == "" {
			return fmt.Errorf("--name is required")
		}
		overwrite, _ := cmd.Flags().GetBool("overwrite")
		if dryRun {
			fmt.Printf("[dry-run] Would save document %s as template \"%s\"\n", id, name)
			return nil
		}
		code, err := model.DocSaveAsTemplate(id, name, overwrite)
		if err != nil {
			return err
		}
		if code == 1 {
			return fmt.Errorf("template already exists, use --overwrite to replace: %s", name)
		}
		fmt.Printf("%s.md\n", name)
		return nil
	},
}

View on GitHub (pinned to 9f775e8a12)