-
Notifications
You must be signed in to change notification settings - Fork 385
✨ Improved Command Line Interface #2667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SnaveSutit
wants to merge
12
commits into
JannisX11:next
Choose a base branch
from
SnaveSutit:feat/cli-improvements
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+412
−28
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ff4f608
🚧 Started work on an improved CLI
SnaveSutit a19cf63
Fix `-v, --version` option
SnaveSutit 2092e95
Improve `process.env` typing
SnaveSutit a746784
Add missing `-v` shorthand to version option
SnaveSutit 98048ed
Improve CLI UX
SnaveSutit bdf49ef
Make the `Blockbench.log` prefix just slightly fancier.
SnaveSutit be70dca
Fixes and improvements
SnaveSutit 1858469
Add `--hidden` option
SnaveSutit 04b097c
Delete test-plugin.js
SnaveSutit 18b1574
Fix call order for launching message
SnaveSutit f3679b0
Fix backwards condition
SnaveSutit de27ac3
Fix incorrect variable name in URL plugin loading
SnaveSutit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ electron-builder.env | |
| node_modules/ | ||
| bundle.js | ||
| workbox-*.js | ||
| service_worker.js | ||
| service_worker.js | ||
| test-env/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // FIXME - This file should be removed before the PR is merged! | ||
| { | ||
| "files.exclude": { | ||
| "**/.git": true, | ||
| "**/node_modules": true | ||
| }, | ||
| "editor.formatOnSave": false, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| const { app, ipcMain } = require('electron') | ||
| const PACKAGE = require('../package.json') | ||
| const { Command } = require('commander') | ||
| const pathjs = require('path') | ||
|
|
||
| const program = new Command() | ||
|
|
||
| program.name('blockbench').description(PACKAGE.description) | ||
|
|
||
| program | ||
| .option('-v, --version', 'output the version number', () => { | ||
| app.terminal.log('NO_PREFIX', PACKAGE.version) | ||
| app.exit(0) | ||
| }) | ||
| .option('--userData <path>', 'change the folder Blockbench uses to store user data') | ||
| .option('--no-auto-update', 'disables auto update') | ||
| .option('--install-custom-plugins <paths...>', 'install plugins from the given paths or URLS on startup') | ||
| .option('--install-plugins <ids...>', 'install plugins by ID from the Blockbench plugin repository on startup') | ||
| .option('--clean-installed-plugins', 'remove all installed plugins on startup') | ||
| .option('--open-dev-tools', 'open the developer tools on startup') | ||
| .option('--hidden', 'hide the main window') | ||
| // Custom Error Handling | ||
| .exitOverride(error => { | ||
| switch (error.code) { | ||
| case 'commander.help': | ||
| case 'commander.helpDisplayed': | ||
| case 'commander.version': | ||
| app.exit(0) | ||
| case 'commander.unknownOption': | ||
| case 'commander.excessArguments': | ||
| // Uses ANSI escape codes to clear the previous line and print a warning message. | ||
| app.terminal.log('NO_PREFIX', '\x1b[1A\x1b[2K\x1b[33mUse --help to see available options\x1b[0m') | ||
| app.exit(1) | ||
| default: | ||
| app.terminal.error('\x1b[2;31m%s\x1b[0m', error) | ||
| app.exit(1) | ||
| } | ||
| }) | ||
| .configureOutput({ | ||
| getOutHasColors: () => true, | ||
| writeErr: str => { | ||
| console.error('\x1b[91m%s\x1b[0m', str) | ||
| }, | ||
| }) | ||
| // Custom Help Styling | ||
| .configureHelp({ | ||
| styleTitle(str) { | ||
| return `\x1b[1m${str}\x1b[0m` | ||
| }, | ||
| styleCommandText(str) { | ||
| return `\x1b[36m${str}\x1b[0m` | ||
| }, | ||
| styleCommandDescription(str) { | ||
| return `\x1b[1A\x1b[2K\x1b[35m${str}\x1b[0m` | ||
| }, | ||
| styleDescriptionText(str) { | ||
| return `\x1b[3m${str}\x1b[0m` | ||
| }, | ||
| styleOptionText(str) { | ||
| return `\x1b[32m${str}\x1b[0m` | ||
| }, | ||
| styleArgumentText(str) { | ||
| return `\x1b[33m${str}\x1b[0m` | ||
| }, | ||
| styleSubcommandText(str) { | ||
| return `\x1b[34m${str}\x1b[0m` | ||
| }, | ||
| }) | ||
|
|
||
| /** | ||
| * Makes sure the environment variables are set to defaults if they are not set. | ||
| * | ||
| * Allows for overriding the default values by setting the environment variables before starting Blockbench. | ||
| */ | ||
| function affirmEnvironmentVariables() { | ||
| process.env.BLOCKBENCH_AUTO_UPDATE ??= 'ENABLED' | ||
| process.env.BLOCKBENCH_CLEAN_INSTALLED_PLUGINS ??= 'FALSE' | ||
| process.env.BLOCKBENCH_INSTALL_CUSTOM_PLUGINS ??= '' | ||
| process.env.BLOCKBENCH_INSTALL_PLUGINS ??= '' | ||
| process.env.BLOCKBENCH_OPEN_DEV_TOOLS ??= 'FALSE' | ||
| process.env.BLOCKBENCH_USER_DATA ??= app.getPath('userData') | ||
| process.env.BLOCKBENCH_HIDDEN ??= 'FALSE' | ||
| } | ||
|
|
||
| function parseCLI() { | ||
| // Parse command line arguments. | ||
| program.parse() | ||
| /** | ||
| * @type {{ userData?: string, autoUpdate?: boolean, withPluginFiles?: string[], withPluginUrls?: string[] }} | ||
| */ | ||
| let { | ||
| userData, | ||
| autoUpdate, | ||
| installCustomPlugins, | ||
| installPlugins, | ||
| openDevTools, | ||
| cleanInstalledPlugins, | ||
| hidden, | ||
| } = program.opts() | ||
|
|
||
| // --no-auto-update | ||
| if (autoUpdate === false) { | ||
| process.env.BLOCKBENCH_AUTO_UPDATE = 'DISABLED' | ||
| } | ||
|
|
||
| // --userData | ||
| if (userData) { | ||
| if (!pathjs.isAbsolute(userData)) { | ||
| // Automatically resolve relative paths. | ||
| userData = pathjs.resolve(userData) | ||
| } | ||
| process.env.BLOCKBENCH_USER_DATA = userData | ||
| } | ||
| app.setPath('userData', process.env.BLOCKBENCH_USER_DATA) | ||
|
|
||
| // --clean-installed-plugins | ||
| if (cleanInstalledPlugins) { | ||
| process.env.BLOCKBENCH_CLEAN_INSTALLED_PLUGINS = 'TRUE' | ||
| } | ||
| // --install-custom-plugins | ||
| if (installCustomPlugins?.length > 0) { | ||
| process.env.BLOCKBENCH_INSTALL_CUSTOM_PLUGINS = installCustomPlugins.join(',') | ||
| } | ||
| // --install-plugins | ||
| if (installPlugins?.length > 0) { | ||
| process.env.BLOCKBENCH_INSTALL_PLUGINS = installPlugins.join(',') | ||
| } | ||
| // --open-dev-tools | ||
| if (openDevTools) { | ||
| process.env.BLOCKBENCH_OPEN_DEV_TOOLS = 'TRUE' | ||
| } | ||
| // --hidden | ||
| if (hidden) { | ||
| process.env.BLOCKBENCH_HIDDEN = 'TRUE' | ||
| } | ||
| } | ||
|
|
||
| module.exports = function cli() { | ||
| affirmEnvironmentVariables() | ||
|
|
||
| try { | ||
| parseCLI() | ||
| } catch (error) { | ||
| app.terminal.error(error) | ||
| app.exit(1) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.