-
Notifications
You must be signed in to change notification settings - Fork 0
Include context command functionality #98
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ffb1b0a
Include context command functionality
wolfo951 f146974
Fixed linter errors
wolfo951 ca01635
Included missing import
wolfo951 946b524
Add iModel and iTwin verification
wolfo951 95a7d4d
Add integration tests
wolfo951 edaf473
Add documentation for the commands and remove mentions of session
wolfo951 1238d37
Update to include short flags in the docs
wolfo951 dcd0e6f
Merge branch 'main' of https://github.com/iTwin/itwin-cli into wolfo9…
wolfo951 0638144
Fixing integration tests
wolfo951 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
| import BaseCommand from "../../extensions/base-command.js"; | ||
|
|
||
| export default class ClearContext extends BaseCommand { | ||
| static description = "Clear the context of the current session."; | ||
|
|
||
| static examples = [ | ||
| { | ||
| command: `<%= config.bin %> <%= command.id %>`, | ||
| description: 'Example 1: Clear the context of the current session' | ||
| } | ||
| ]; | ||
|
|
||
| async run() { | ||
| this.clearContext(); | ||
| return this.logAndReturnResult({ result: "Context cleared." }); | ||
| } | ||
| } |
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,17 @@ | ||
| import BaseCommand from "../../extensions/base-command.js"; | ||
|
|
||
| export default class InfoContext extends BaseCommand { | ||
| static description = "Display the current context of the session."; | ||
|
|
||
| static examples = [ | ||
| { | ||
| command: `<%= config.bin %> <%= command.id %>`, | ||
| description: 'Example 1: Display the current context of the session' | ||
| } | ||
| ]; | ||
|
|
||
| async run() { | ||
| const context = this.getContext(); | ||
| return this.logAndReturnResult(context); | ||
| } | ||
| } |
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,59 @@ | ||
| import { IModel } from "@itwin/imodels-client-management"; | ||
| import { ITwin } from "@itwin/itwins-client"; | ||
| import { Flags } from "@oclif/core"; | ||
|
|
||
| import BaseCommand from "../../extensions/base-command.js"; | ||
|
|
||
| export default class SetContext extends BaseCommand { | ||
| static description = "Create a new context for the current session."; | ||
|
|
||
| static examples = [ | ||
| { | ||
| command: `<%= config.bin %> <%= command.id %>`, | ||
| description: 'Example 1: Create a new context for the current session' | ||
| } | ||
| ]; | ||
|
|
||
| static flags = { | ||
| "imodel-id": Flags.string({ | ||
| char: 'm', | ||
| description: "The ID of the iModel to create a context for.", | ||
| helpValue: '<string>', | ||
| required: false | ||
| }), | ||
| "itwin-id": Flags.string({ | ||
| char: 'i', | ||
| description: "The ID of the iTwin to create a context for.", | ||
| helpValue: '<string>', | ||
| required: false, | ||
| }), | ||
| }; | ||
|
|
||
| async run() { | ||
| const { flags } = await this.parse(SetContext); | ||
| const iModelId = flags["imodel-id"]; | ||
| let iTwinId = flags["itwin-id"]; | ||
|
|
||
| // If iModelId is provided, check if it exists | ||
| // and verify that it belongs to the specified iTwinId | ||
| if(iModelId) { | ||
| const iModel = await this.runCommand<IModel>("imodel:info", ["--imodel-id", iModelId]); | ||
| if(iTwinId && iModel.iTwinId !== flags["itwin-id"]) { | ||
| this.error("The iModel ID does not match the iTwin ID."); | ||
| } | ||
|
|
||
| iTwinId = iModel.iTwinId; | ||
| } | ||
| // If iTwinId is provided, check if it exists | ||
| else if (iTwinId) { | ||
| await this.runCommand<ITwin>("itwin:info", ["--itwin-id", iTwinId]); | ||
| } | ||
| // If neither iModelId nor iTwinId is provided, throw an error | ||
| else { | ||
| this.error("Either --itwin-id or --imodel-id must be provided."); | ||
| } | ||
|
|
||
| const context = await this.setContext(iTwinId, iModelId); | ||
| return this.logAndReturnResult(context); | ||
| } | ||
| } | ||
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
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,4 @@ | ||
| export type UserContext = { | ||
| iModelId?: string; | ||
| iTwinId: string; | ||
| } |
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.