1- // Projects command - search for SonarQube projects
2-
1+ /*
2+ * SonarQube CLI
3+ * Copyright (C) 2026 SonarSource Sàrl
4+ * mailto:info AT sonarsource DOT com
5+ *
6+ * This program is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 3 of the License, or (at your option) any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public License
17+ * along with this program; if not, write to the Free Software Foundation,
18+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+ */
320import { SonarQubeClient } from '../sonarqube/client.js' ;
421import { ProjectsClient , MAX_PAGE_SIZE } from '../sonarqube/projects.js' ;
522import { getToken } from '../lib/keychain.js' ;
@@ -30,7 +47,9 @@ export async function projectsSearchCommand(options: ProjectsSearchOptions): Pro
3047
3148 const pageSize = options . pageSize ?? MAX_PAGE_SIZE ;
3249 if ( pageSize <= 0 || pageSize > MAX_PAGE_SIZE ) {
33- throw new Error ( `--page-size must be greater than 0 and less than or equal to ${ MAX_PAGE_SIZE } ` ) ;
50+ throw new Error (
51+ `--page-size must be greater than 0 and less than or equal to ${ MAX_PAGE_SIZE } ` ,
52+ ) ;
3453 }
3554
3655 const client = new SonarQubeClient ( activeConnection . serverUrl , token ) ;
@@ -40,18 +59,20 @@ export async function projectsSearchCommand(options: ProjectsSearchOptions): Pro
4059 q : options . query ,
4160 ps : pageSize ,
4261 p : options . page ?? 1 ,
43- organization : activeConnection . orgKey
62+ organization : activeConnection . orgKey ,
4463 } ) ;
4564
46- const hasNextPage = ( result . paging . pageIndex * result . paging . pageSize ) < result . paging . total ;
47-
48- print ( JSON . stringify ( {
49- projects : result . components . map ( c => ( { key : c . key , name : c . name } ) ) ,
50- paging : {
51- pageIndex : result . paging . pageIndex ,
52- pageSize : result . paging . pageSize ,
53- total : result . paging . total ,
54- hasNextPage
55- }
56- } ) ) ;
65+ const hasNextPage = result . paging . pageIndex * result . paging . pageSize < result . paging . total ;
66+
67+ print (
68+ JSON . stringify ( {
69+ projects : result . components . map ( ( c ) => ( { key : c . key , name : c . name } ) ) ,
70+ paging : {
71+ pageIndex : result . paging . pageIndex ,
72+ pageSize : result . paging . pageSize ,
73+ total : result . paging . total ,
74+ hasNextPage,
75+ } ,
76+ } ) ,
77+ ) ;
5778}
0 commit comments