Skip to content

Commit 6de0534

Browse files
committed
ST6RI-836 Added magic command to change api-base-path
1 parent 57402a0 commit 6de0534

4 files changed

Lines changed: 82 additions & 1 deletion

File tree

org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractive.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ public void setApiBasePath(String apiBasePath) {
137137
this.apiBasePath = apiBasePath;
138138
}
139139

140+
public String getApiBasePath() {
141+
return apiBasePath;
142+
}
143+
140144
public int next() {
141145
this.resource = (XtextResource)this.createResource(counter + SYSML_EXTENSION);
142146
this.addInputResource(this.resource);
@@ -249,6 +253,18 @@ public String help(String command) {
249253
help(command, Collections.emptyList());
250254
}
251255

256+
public String apiBasePath(String apiBasePath, List<String> help) {
257+
if (!help.isEmpty()) {
258+
return SysMLInteractiveHelp.getApiBasePathHelp();
259+
}
260+
261+
if (!Strings.isNullOrEmpty(apiBasePath)) {
262+
setApiBasePath(apiBasePath);
263+
}
264+
265+
return getApiBasePath();
266+
}
267+
252268
public String eval(String input, String targetName, List<String> help) {
253269
if (Strings.isNullOrEmpty(input)) {
254270
this.counter++;

org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class SysMLInteractiveHelp {
3838
private static final String GENERAL_HELP_STRING =
3939
"The following SysML v2 magic commands are available.\n"
4040
+ "For help on a specific command, use \"%help <COMMAND>\" or \"%<cmd> -h\".\n\n"
41+
+ "%api-base-path\t Sets and prints the current api base path"
4142
+ "%eval\t\tEvaluate a given expression.\n"
4243
+ "%export\t\tSave a file of the JSON representation of the abstract syntax tree rooted in the named element.\n"
4344
+ "%help\t\tGet a list of available commands or help on a specific command\n"
@@ -115,6 +116,11 @@ public class SysMLInteractiveHelp {
115116
"Usage: %export <NAME>\n\n"
116117
+ "Save a file containing the complete JSON representation of the abstract syntax tree rooted in <NAME>.\n"
117118
+ "<NAME> must be fully qualified.\n";
119+
120+
private static final String API_BASE_PATH_HELP_STRING =
121+
"Usage: %api-base-path [<BASE PATH>]\n\n"
122+
+ "Sets the current api base path\n"
123+
+ "If no argument is passed it prints the current api base path";
118124

119125
public static String getGeneralHelp() {
120126
return GENERAL_HELP_STRING;
@@ -152,6 +158,10 @@ public static String getExportHelp() {
152158
return EXPORT_HELP_STRING;
153159
}
154160

161+
public static String getApiBasePathHelp() {
162+
return API_BASE_PATH_HELP_STRING;
163+
}
164+
155165
private static Map<String, String> commandHelpMap = createCommandHelpMap();
156166

157167
private static Map<String, String> createCommandHelpMap() {
@@ -170,5 +180,4 @@ private static Map<String, String> createCommandHelpMap() {
170180
public static String getHelpString(String command) {
171181
return commandHelpMap.get(command);
172182
}
173-
174183
}

org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/SysMLKernel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public SysMLKernel() {
8080
this.magics.registerMagics(Viz.class);
8181
this.magics.registerMagics(View.class);
8282
this.magics.registerMagics(Export.class);
83+
this.magics.registerMagics(ApiBasePath.class);
8384

8485
this.magicParser = new MyMagicParser();
8586
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* SysML 2 Pilot Implementation
3+
* Copyright (C) 2025 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
* Contributors:
21+
* Laszlo Gati, MDS
22+
*/
23+
package org.omg.sysml.jupyter.kernel.magic;
24+
25+
import java.util.List;
26+
import java.util.Map;
27+
28+
import org.omg.sysml.interactive.SysMLInteractive;
29+
import org.omg.sysml.jupyter.kernel.ISysML;
30+
31+
import io.github.spencerpark.jupyter.kernel.magic.registry.LineMagic;
32+
import io.github.spencerpark.jupyter.kernel.magic.registry.MagicsArgs;
33+
34+
public class ApiBasePath {
35+
36+
private static final MagicsArgs SHOW_ARGS = MagicsArgs.builder().onlyKnownKeywords().onlyKnownFlags()
37+
.optional("basePath")
38+
.flag("help", 'h', "true")
39+
.build();
40+
41+
@LineMagic("api-base-path")
42+
public static String apiBasePath(List<String> args) {
43+
Map<String, List<String>> vals = SHOW_ARGS.parse(args);
44+
List<String> basePaths = vals.get("basePath");
45+
String basePath = basePaths.isEmpty()? null: basePaths.get(0);
46+
47+
SysMLInteractive interactive = ISysML.getKernelInstance().getInteractive();
48+
49+
if (basePath != null) {
50+
interactive.setApiBasePath(basePath);
51+
}
52+
53+
return "Api base path is: " + ISysML.getKernelInstance().getInteractive().getApiBasePath();
54+
}
55+
}

0 commit comments

Comments
 (0)