@@ -135,4 +135,202 @@ program
135135 }
136136 } ) ;
137137
138+ // Create command
139+ program
140+ . command ( 'create <title> <spaceKey>' )
141+ . description ( 'Create a new Confluence page' )
142+ . option ( '-f, --file <file>' , 'Read content from file' )
143+ . option ( '-c, --content <content>' , 'Page content as string' )
144+ . option ( '--format <format>' , 'Content format (storage, html, markdown)' , 'storage' )
145+ . action ( async ( title , spaceKey , options ) => {
146+ const analytics = new Analytics ( ) ;
147+ try {
148+ const config = getConfig ( ) ;
149+ const client = new ConfluenceClient ( config ) ;
150+
151+ let content = '' ;
152+
153+ if ( options . file ) {
154+ const fs = require ( 'fs' ) ;
155+ if ( ! fs . existsSync ( options . file ) ) {
156+ throw new Error ( `File not found: ${ options . file } ` ) ;
157+ }
158+ content = fs . readFileSync ( options . file , 'utf8' ) ;
159+ } else if ( options . content ) {
160+ content = options . content ;
161+ } else {
162+ throw new Error ( 'Either --file or --content option is required' ) ;
163+ }
164+
165+ const result = await client . createPage ( title , spaceKey , content , options . format ) ;
166+
167+ console . log ( chalk . green ( '✅ Page created successfully!' ) ) ;
168+ console . log ( `Title: ${ chalk . blue ( result . title ) } ` ) ;
169+ console . log ( `ID: ${ chalk . blue ( result . id ) } ` ) ;
170+ console . log ( `Space: ${ chalk . blue ( result . space . name ) } (${ result . space . key } )` ) ;
171+ console . log ( `URL: ${ chalk . gray ( `https://${ config . domain } /wiki${ result . _links . webui } ` ) } ` ) ;
172+
173+ analytics . track ( 'create' , true ) ;
174+ } catch ( error ) {
175+ analytics . track ( 'create' , false ) ;
176+ console . error ( chalk . red ( 'Error:' ) , error . message ) ;
177+ process . exit ( 1 ) ;
178+ }
179+ } ) ;
180+
181+ // Create child page command
182+ program
183+ . command ( 'create-child <title> <parentId>' )
184+ . description ( 'Create a new Confluence page as a child of another page' )
185+ . option ( '-f, --file <file>' , 'Read content from file' )
186+ . option ( '-c, --content <content>' , 'Page content as string' )
187+ . option ( '--format <format>' , 'Content format (storage, html, markdown)' , 'storage' )
188+ . action ( async ( title , parentId , options ) => {
189+ const analytics = new Analytics ( ) ;
190+ try {
191+ const config = getConfig ( ) ;
192+ const client = new ConfluenceClient ( config ) ;
193+
194+ // Get parent page info to get space key
195+ const parentInfo = await client . getPageInfo ( parentId ) ;
196+ const spaceKey = parentInfo . space . key ;
197+
198+ let content = '' ;
199+
200+ if ( options . file ) {
201+ const fs = require ( 'fs' ) ;
202+ if ( ! fs . existsSync ( options . file ) ) {
203+ throw new Error ( `File not found: ${ options . file } ` ) ;
204+ }
205+ content = fs . readFileSync ( options . file , 'utf8' ) ;
206+ } else if ( options . content ) {
207+ content = options . content ;
208+ } else {
209+ throw new Error ( 'Either --file or --content option is required' ) ;
210+ }
211+
212+ const result = await client . createChildPage ( title , spaceKey , parentId , content , options . format ) ;
213+
214+ console . log ( chalk . green ( '✅ Child page created successfully!' ) ) ;
215+ console . log ( `Title: ${ chalk . blue ( result . title ) } ` ) ;
216+ console . log ( `ID: ${ chalk . blue ( result . id ) } ` ) ;
217+ console . log ( `Parent: ${ chalk . blue ( parentInfo . title ) } (${ parentId } )` ) ;
218+ console . log ( `Space: ${ chalk . blue ( result . space . name ) } (${ result . space . key } )` ) ;
219+ console . log ( `URL: ${ chalk . gray ( `https://${ config . domain } /wiki${ result . _links . webui } ` ) } ` ) ;
220+
221+ analytics . track ( 'create_child' , true ) ;
222+ } catch ( error ) {
223+ analytics . track ( 'create_child' , false ) ;
224+ console . error ( chalk . red ( 'Error:' ) , error . message ) ;
225+ process . exit ( 1 ) ;
226+ }
227+ } ) ;
228+
229+ // Update command
230+ program
231+ . command ( 'update <pageId>' )
232+ . description ( 'Update an existing Confluence page' )
233+ . option ( '-t, --title <title>' , 'New page title (optional)' )
234+ . option ( '-f, --file <file>' , 'Read content from file' )
235+ . option ( '-c, --content <content>' , 'Page content as string' )
236+ . option ( '--format <format>' , 'Content format (storage, html, markdown)' , 'storage' )
237+ . action ( async ( pageId , options ) => {
238+ const analytics = new Analytics ( ) ;
239+ try {
240+ const config = getConfig ( ) ;
241+ const client = new ConfluenceClient ( config ) ;
242+
243+ let content = '' ;
244+
245+ if ( options . file ) {
246+ const fs = require ( 'fs' ) ;
247+ if ( ! fs . existsSync ( options . file ) ) {
248+ throw new Error ( `File not found: ${ options . file } ` ) ;
249+ }
250+ content = fs . readFileSync ( options . file , 'utf8' ) ;
251+ } else if ( options . content ) {
252+ content = options . content ;
253+ } else {
254+ throw new Error ( 'Either --file or --content option is required' ) ;
255+ }
256+
257+ const result = await client . updatePage ( pageId , options . title , content , options . format ) ;
258+
259+ console . log ( chalk . green ( '✅ Page updated successfully!' ) ) ;
260+ console . log ( `Title: ${ chalk . blue ( result . title ) } ` ) ;
261+ console . log ( `ID: ${ chalk . blue ( result . id ) } ` ) ;
262+ console . log ( `Version: ${ chalk . blue ( result . version . number ) } ` ) ;
263+ console . log ( `URL: ${ chalk . gray ( `https://${ config . domain } /wiki${ result . _links . webui } ` ) } ` ) ;
264+
265+ analytics . track ( 'update' , true ) ;
266+ } catch ( error ) {
267+ analytics . track ( 'update' , false ) ;
268+ console . error ( chalk . red ( 'Error:' ) , error . message ) ;
269+ process . exit ( 1 ) ;
270+ }
271+ } ) ;
272+
273+ // Edit command - opens page content for editing
274+ program
275+ . command ( 'edit <pageId>' )
276+ . description ( 'Get page content for editing' )
277+ . option ( '-o, --output <file>' , 'Save content to file' )
278+ . action ( async ( pageId , options ) => {
279+ const analytics = new Analytics ( ) ;
280+ try {
281+ const config = getConfig ( ) ;
282+ const client = new ConfluenceClient ( config ) ;
283+ const pageData = await client . getPageForEdit ( pageId ) ;
284+
285+ console . log ( chalk . blue ( 'Page Information:' ) ) ;
286+ console . log ( `Title: ${ chalk . green ( pageData . title ) } ` ) ;
287+ console . log ( `ID: ${ chalk . green ( pageData . id ) } ` ) ;
288+ console . log ( `Version: ${ chalk . green ( pageData . version ) } ` ) ;
289+ console . log ( `Space: ${ chalk . green ( pageData . space . name ) } (${ pageData . space . key } )` ) ;
290+ console . log ( '' ) ;
291+
292+ if ( options . output ) {
293+ const fs = require ( 'fs' ) ;
294+ fs . writeFileSync ( options . output , pageData . content ) ;
295+ console . log ( chalk . green ( `✅ Content saved to: ${ options . output } ` ) ) ;
296+ console . log ( chalk . yellow ( '💡 Edit the file and use "confluence update" to save changes' ) ) ;
297+ } else {
298+ console . log ( chalk . blue ( 'Page Content:' ) ) ;
299+ console . log ( pageData . content ) ;
300+ }
301+
302+ analytics . track ( 'edit' , true ) ;
303+ } catch ( error ) {
304+ analytics . track ( 'edit' , false ) ;
305+ console . error ( chalk . red ( 'Error:' ) , error . message ) ;
306+ process . exit ( 1 ) ;
307+ }
308+ } ) ;
309+
310+ // Find page by title command
311+ program
312+ . command ( 'find <title>' )
313+ . description ( 'Find a page by title' )
314+ . option ( '-s, --space <spaceKey>' , 'Limit search to specific space' )
315+ . action ( async ( title , options ) => {
316+ const analytics = new Analytics ( ) ;
317+ try {
318+ const config = getConfig ( ) ;
319+ const client = new ConfluenceClient ( config ) ;
320+ const pageInfo = await client . findPageByTitle ( title , options . space ) ;
321+
322+ console . log ( chalk . blue ( 'Page found:' ) ) ;
323+ console . log ( `Title: ${ chalk . green ( pageInfo . title ) } ` ) ;
324+ console . log ( `ID: ${ chalk . green ( pageInfo . id ) } ` ) ;
325+ console . log ( `Space: ${ chalk . green ( pageInfo . space . name ) } (${ pageInfo . space . key } )` ) ;
326+ console . log ( `URL: ${ chalk . gray ( `https://${ config . domain } /wiki${ pageInfo . url } ` ) } ` ) ;
327+
328+ analytics . track ( 'find' , true ) ;
329+ } catch ( error ) {
330+ analytics . track ( 'find' , false ) ;
331+ console . error ( chalk . red ( 'Error:' ) , error . message ) ;
332+ process . exit ( 1 ) ;
333+ }
334+ } ) ;
335+
138336program . parse ( ) ;
0 commit comments