33* See LICENSE.md in the project root for license terms and full copyright notice.
44*--------------------------------------------------------------------------------------------*/
55
6+ import { Changeset } from "@itwin/imodels-client-management" ;
67import { Flags } from "@oclif/core" ;
78import open from 'open' ;
89import { deflate } from "pako" ;
@@ -15,19 +16,23 @@ export default class CesiumSandcastle extends BaseCommand {
1516
1617 static examples = [
1718 {
18- command : `<%= config.bin %> <%= command.id %> --imodel-id " 5e19bee0-3aea-4355-a9f0-c6df9989ee7d" --changeset-id "2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5" ` ,
19- description : 'Example 1: Get a link to a specific changeset of an iModel in Cesium Sandcastle'
19+ command : `<%= config.bin %> <%= command.id %> --imodel-id 5e19bee0-3aea-4355-a9f0-c6df9989ee7d` ,
20+ description : 'Example 1: Get a link to an iModel in Cesium Sandcastle'
2021 } ,
2122 {
22- command : `<%= config.bin %> <%= command.id %> --imodel-id "5e19bee0-3aea-4355-a9f0-c6df9989ee7d" --changeset-id "2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5" --open` ,
23- description : 'Example 2: Get a link to a specific changeset of an iModel in Cesium Sandcastle and open the URL in the browser'
23+ command : `<%= config.bin %> <%= command.id %> --imodel-id 5e19bee0-3aea-4355-a9f0-c6df9989ee7d --changeset-id 2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5` ,
24+ description : 'Example 2: Get a link to a specific changeset of an iModel in Cesium Sandcastle'
25+ } ,
26+ {
27+ command : `<%= config.bin %> <%= command.id %> --imodel-id 5e19bee0-3aea-4355-a9f0-c6df9989ee7d --changeset-id 2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5 --open` ,
28+ description : 'Example 3: Get a link to a specific changeset of an iModel in Cesium Sandcastle and open the URL in the browser'
2429 }
2530 ] ;
2631
2732 static flags = {
2833 "changeset-id" : Flags . string ( {
29- description : "Changeset id to be viewed in Cesium Sandcastle." ,
30- required : true
34+ description : "Changeset id to be viewed in Cesium Sandcastle. If not provided, the latest changeset will be used. " ,
35+ required : false
3136 } ) ,
3237 "imodel-id" : Flags . string ( {
3338 char : "m" ,
@@ -96,7 +101,17 @@ export default class CesiumSandcastle extends BaseCommand {
96101 async run ( ) {
97102 const { flags } = await this . parse ( CesiumSandcastle ) ;
98103
99- const exportInfo : ExportInfo = await this . getOrCreateExport ( flags [ "imodel-id" ] , flags [ "changeset-id" ] ) ;
104+ let changesetId = flags [ "changeset-id" ] ;
105+ if ( changesetId === undefined ) {
106+ const existingChangesets = await this . runCommand < Changeset [ ] > ( "imodel:changeset:list" , [ "-m" , flags [ "imodel-id" ] , "--top" , "1" , "--order-by" , "desc" ] ) ;
107+ if ( existingChangesets . length === 0 ) {
108+ this . error ( `No changesets found for iModel: ${ flags [ "imodel-id" ] } ` ) ;
109+ }
110+
111+ changesetId = existingChangesets [ 0 ] . id ;
112+ }
113+
114+ const exportInfo : ExportInfo = await this . getOrCreateExport ( flags [ "imodel-id" ] , changesetId ) ;
100115
101116 this . log ( `Extracting tileset URL from export info` ) ;
102117 const tilesetUrl : string = extractTileSetUrl ( exportInfo ) ;
0 commit comments