You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Plugins can extend the ObjectStack CLI (`os`) with custom commands. This enables third-party packages — such as marketplace tools, deployment utilities, or domain-specific workflows — to register new top-level subcommands.
Once installed, the new commands appear in `os --help` and can be invoked directly:
615
+
616
+
```bash
617
+
# List available commands (includes plugin commands)
618
+
os --help
619
+
620
+
# Use marketplace commands
621
+
os marketplace search "crm"
622
+
os marketplace install com.acme.crm
623
+
os marketplace publish ./dist --public
624
+
```
625
+
626
+
#### Complete Example: Deployment Plugin
627
+
628
+
Here's a full example of a deployment CLI plugin:
629
+
630
+
```typescript
631
+
// @acme/plugin-deploy/src/cli.ts
632
+
import { Command } from'commander';
633
+
634
+
const deployCommand =newCommand('deploy')
635
+
.description('Deploy ObjectStack app to cloud')
636
+
.addCommand(
637
+
newCommand('staging')
638
+
.description('Deploy to staging environment')
639
+
.option('--skip-tests', 'Skip pre-deploy tests')
640
+
.action(async (options) => {
641
+
console.log('Deploying to staging...');
642
+
if (!options.skipTests) {
643
+
console.log('Running tests first...');
644
+
}
645
+
// deploy logic
646
+
})
647
+
)
648
+
.addCommand(
649
+
newCommand('production')
650
+
.description('Deploy to production')
651
+
.option('--confirm', 'Skip confirmation prompt')
652
+
.action(async (options) => {
653
+
if (!options.confirm) {
654
+
// prompt for confirmation
655
+
}
656
+
console.log('Deploying to production...');
657
+
})
658
+
)
659
+
.addCommand(
660
+
newCommand('status')
661
+
.description('Check deployment status')
662
+
.action(async () => {
663
+
console.log('Checking deployment status...');
664
+
})
665
+
);
666
+
667
+
exportconst commands = [deployCommand];
668
+
```
669
+
670
+
```typescript
671
+
// @acme/plugin-deploy/objectstack.config.ts
672
+
import { defineStack } from'@objectstack/spec';
673
+
674
+
exportdefaultdefineStack({
675
+
manifest: {
676
+
id: 'com.acme.deploy',
677
+
version: '1.0.0',
678
+
type: 'plugin',
679
+
name: 'Deploy Plugin',
680
+
contributes: {
681
+
commands: [
682
+
{
683
+
name: 'deploy',
684
+
description: 'Deploy ObjectStack app to cloud',
685
+
module: './dist/cli.js',
686
+
},
687
+
],
688
+
},
689
+
},
690
+
});
691
+
```
692
+
693
+
Usage:
694
+
695
+
```bash
696
+
os deploy staging --skip-tests
697
+
os deploy production --confirm
698
+
os deploy status
699
+
```
700
+
701
+
<Callouttype="info">
702
+
**Graceful Degradation**: If a plugin command fails to load (e.g., missing dependency), the CLI logs a warning in `DEBUG` mode and continues with built-in commands. Plugin commands never block the CLI.
703
+
</Callout>
704
+
468
705
---
469
706
470
707
## Directory Structure Convention
@@ -480,6 +717,7 @@ plugin-my-feature/
480
717
├── CHANGELOG.md
481
718
└── src/
482
719
├── index.ts # Entry point (required)
720
+
├── cli.ts # CLI commands (optional, for contributes.commands)
0 commit comments