CLI: Add Sites list command - #1742
Conversation
|
This is the smallest change possible. I'm considering defining a |
There was a problem hiding this comment.
Thanks for starting the CLI sites work @youknowriad
This is a solid starting point!
I would recommend focusing solely on appdata.sites and excluding newSites from this implementation.
newSites was created as a workaround for the CLI preview command to create sites, since the CLI lacked site management capabilities. Now that we're adding proper site management, we should update the preview command to use it and remove newSites entirely.
| registerUpdateCommand( previewYargs ); | ||
| previewYargs.demandCommand( 1, __( 'You must provide a valid command' ) ); | ||
| } ) | ||
| .command( 'sites', __( 'Manage local sites' ), ( sitesYargs ) => { |
There was a problem hiding this comment.
We should put these commands behind a feature flag for now.
It would be better to ship the complete CLI sites functionality as a full release, with all subcommands (list, add, remove, start, stop), proper documentation, and coordinated marketing. This prevents
users from discovering a partially-implemented feature.
What do you think?
There was a problem hiding this comment.
I agree, do we have a precedent of using feature flags to hide CLI features? I know we have feature flags in the app but I'm unsure how these translate to the CLI.
There was a problem hiding this comment.
AFAIK we haven't used feature flags in the CLI.
For now I would suggest using a env var to conditionally add the sites commands to the CLI in index.ts.
If you want I can take on that issue, and propose a solution on how we can manage feature flags across Studio and CLI.
There was a problem hiding this comment.
@bcotrim Please go ahead I'd love that :)
There was a problem hiding this comment.
@youknowriad , @bcotrim , I've created a quick PR to add a feature flag using ENABLE_CLI_V2 #1759
Let me know what you think.
This is good context for me. In my prototype I actually kind of avoided newSites entirely except for the list command. But I can exclude it from here and maybe ultimately get rid of it once we have the full "create commands" implemented.. |
6e57a41 to
1a8355d
Compare
|
how is this looking? |
There was a problem hiding this comment.
@youknowriad, thanks for pushing the CLI project forward, and splitting the functionality in small PRs.
I tested it by running npm run cli:build and then node ./dist/cli/main.js sites list, and it worked as expected.
I left a suggestion to use the same properties in both formats.
I wonder if we should add more data to the list, like the WordPress version of each site.
For the "running" status, I had the idea of checking if the site is up on the given port, or even building an endpoint at Express.js level that could return if the site is running.
I like how the subcommands are grouped under studio sites main command:
I see that Studio CLI adds the --path parameter as a global option. We might consider adding it at the command level instead or just removing it from the sites command, as I don't see it being useful for this command.
It's looking great! ✨ I’ll be happy to help by submitting new PRs to add functionality. |
|
I looked at the type for |
Feels like just duplicate work (assuming the flag is persisted properly). We might need this later I give it to you but I prefer to keep things small for now. |
Sounds good to me, so add it to all the preview commands right? |
The WordPress version is not saved in appData and it's read directly from each sites's Lines 906 to 923 in 66e76f8 |
Ok, I guess it's better to add a common library to do that and do it in its own PR. I created a dedicated issue for it STU-788 |
Yesterday I created this PR that hides the --path option from the |
|
@youknowriad thanks for the contribution - the list works well for me. Could we change |
Works for me, but I'm not fully convinced. I think once we have site start/stop, we'll have to reshuffle the command names again. I think we'll have a better idea what works and what doesn't later. |
Why would we need to reshuffle it after adding start/stop? I think the singular names would make logical sense and would be consistent with WP CLI. Studio currently has those: Now we would add: And later: In WP CLI we have: |
|
For me if you put "start and stop" under "site", you should also put "preview" under "site". But I don't want to get into this discussion right now to be honest, there's no urgency. Let's build what we need and things might clarify later. |
34cf6c0 to
9e368b4
Compare
|
I see, thanks @youknowriad . |
sejas
left a comment
There was a problem hiding this comment.
The code looks good to me, and now that it's behind a feature flag we can merge this PR. We can always add more fields in the future if necessary.
Currently, the status will be "Stopped" for all sites, but I think it's fine to keep it as a placeholder.
Merging this PR will make it easier to divide the work and add more site commands in different PRs.
| Table | JSON |
|---|---|
![]() |
![]() |
| site.name, | ||
| site.path, | ||
| site.id, | ||
| site.running ? __( 'Running' ) : __( 'Stopped' ), |
There was a problem hiding this comment.
site.running will be always falsy, as it doesn't exist in AppData, so all sites will appear as Stopped until we implement a mechanism to detect whether a site is running or not.
There was a problem hiding this comment.
Oh really, where can I check exactly what things exists in app data or not? I think for now I'm just going to remove this information.
There was a problem hiding this comment.
Do we have a "type" that defines what is saved into appData?
There was a problem hiding this comment.
AppData is available in ~/Library/Application Support/Studio/appdata-v1.json and here is an example of one of my sites:
{
"id": "e1014e86-ece3-4c1f-a1ac-632d7df5bae7",
"name": "Antonio Sejas | <yay> | 123",
"path": "/Users/macbookpro/Studio/my-blog",
"adminPassword": "NWFake1230d0",
"port": 8882,
"phpVersion": "8.0",
"isWpAutoUpdating": false,
"customDomain": "antonio-sejas-yay-123.wp.local",
"enableHttps": false,
"autoStart": true,
"themeDetails": {
"name": "Twenty Twenty-Five/twentytwentyfive-trunk",
"path": "/var/www/html/wp-content/themes/twentytwentyfive-trunk",
"slug": "twentytwentyfive-trunk",
"isBlockTheme": true,
"supportsWidgets": false,
"supportsMenus": false
}
}
The type that better represent it is StoppedSiteDetails:
Lines 14 to 38 in 28ca9ea
There was a problem hiding this comment.
I'm thinking we might need to have that typed properly and shared with both CLI and app at some point to clarify expectations when reading from appData.
There was a problem hiding this comment.
I was basing my info on the SiteDetails type and I was wrong haha.
There was a problem hiding this comment.
Agreed, the AppData type should be common for CLI and the App 💯 .
|
Thanks folks, more PRs coming :) |



Context about this PR pgle0O-QH-p2
See this branch for the full CLI.
Proposed Changes
This PR implements a very simple "list sites" command in the CLI tool. It's the first step towards a more capable and useful CLI tool.
Testing Instructions
npm run cli:buildnode ./dist/cli/main.js sites listIt should list whatever sites you have in your Studio App in the terminal.
Example