Skip to content

xpd new

Create a rule project, or a rule, test case or utility in one Use xpd new to start a rule project or to add a rule, a test case or a utility to one. Run it without a command, and it asks what to create and asks for each missing value. With --yes it never asks, which suits scripts and agents.

Terminal window
xpd new [OPTIONS] [COMMAND]

xpd new --help ends with these lines.

Examples:
xpd new
xpd new project --pack team
xpd new rule team/no-iterrows --pattern '$DF.iterrows()' --message 'Loop over columns instead.' --yes
xpd new rule utc-now --language python --pattern 'datetime.utcnow()' \
--fix 'datetime.now(UTC)' --fix-safety unsafe --message 'utcnow is naive.' --with-test --yes
xpd new test team/no-iterrows --yes
xpd new util new-figure --language python --pattern 'go.Figure($$$)' --yes
Command What it does
xpd new project Create sgconfig.yml, xpd.yml and the rules, rule-tests and utils folders
xpd new rule Create a rule from a pattern, with the Markdown that explains it beside the rule file
xpd new test Create an empty test case for a rule, with no valid or invalid code yet
xpd new util Create a global utility rule, which any rule can use with matches: <name>

--directory <DIR>

The project folder, which holds sgconfig.yml. Nothing is written outside it. Default: the nearest folder at or above the current one with sgconfig.yml, or the current folder for a new project.

-y, --yes

Never ask. Fail when a required flag is missing.

--format <FORMAT>

Print the result as text, or as JSON with createdFiles and modifiedFiles.

Default: text.

Values: text, json.

Terminal window
$ xpd new project --pack team --yes
Created project
created /tmp/project/sgconfig.yml
created /tmp/project/xpd.yml
created /tmp/project/rules/.gitkeep
created /tmp/project/rule-tests/.gitkeep
created /tmp/project/utils/.gitkeep
created /tmp/project/rules/team/.gitkeep
$ xpd new rule team/no-print --pattern 'print($X)' --message 'Use the project logger.' --with-test --yes
Created rule team/no-print
created /tmp/project/rules/team/no-print.yml
created /tmp/project/rules/team/no-print.md
created /tmp/project/rule-tests/team/no-print-test.yml
$ xpd new util print-call --lang python --pattern 'print($X)' --yes
Created util print-call
created /tmp/project/utils/print-call.yml

The commands above write these files. Each folder that project makes also gets an empty .gitkeep.

.
├── sgconfig.yml # ruleDirs: rules, utilDirs: utils, testConfigs: rule-tests
├── xpd.yml # the pack team, with ruleDirs: rules/team
├── rules/team/no-print.yml
├── rules/team/no-print.md # the Markdown that explains team/no-print
├── rule-tests/team/no-print-test.yml # id: team/no-print, valid: [], invalid: []
└── utils/print-call.yml

--format json prints createdFiles and modifiedFiles as absolute paths.

Exit code Meaning
0 The files were written
2 A value is missing with --yes, a file it would write exists, or the rule does not parse. Nothing is written