In general, it’s not easy to pass an argument from the command line to the extension. It requires you to create the extension as a sever extension, and then pass the information from the python side to the JS side using a traitlet.
Basics of making a server app: extension-examples/server-extension at main · jupyterlab/extension-examples · GitHub
Set up the basic server app stuff:
__init__.py:
from ._version import __version__
from .server import MyApp
def _jupyter_labextension_paths():
return [{"src": "labextension", "dest": "myapp"}]
def _jupyter_server_extension_points():
return [
{
"module": "myapp",
"app": MyApp, # <- Note this is not quoted. This is the module
"name": "myapp",
}
]
Replace the server app with what you are doing. In the start-up section of the app, you can assign a variable to be shared with the JS side:
server.py:
from jupyter_server.extension.application
import ExtensionApp
from traitlets import Bool
class MyApp(ExtensionApp):
name = "myapp"
myflag = Bool(False, help="my setting goes here").tag(config=True)
def initialize_settings(self):
super().initialize_settings()
web_app = self.serverapp.web_app
settings = web_app.settings
page_config = settings.setdefault("page_config_data", {})
page_config["my_app_my_flag"] = self.myflag
...
Then, in the JS/TS side of your extension, you can retrieve the value:
index.ts:
...
import { PageConfig } from '@jupyterlab/coreutils';
... (some more code)
const myflag = PageConfig.getOption('my_app_my_flag') === 'true';
... (other code)
(which assumes your variable myflag is a boolean type. Adjust for something else)
Obviously, it’s not finished baking without some extra steps. You need to follow the rest of the server app example about the files required and where to deploy them, and which parts of the build steps are required.
When it’s complete, then arguments can be passed on the command line like:
jupyter lab --MyApp.myflag=True ...