@@ -23,6 +23,13 @@ const timeout = 50000;
2323const config = require ( '../../../../config' ) ;
2424const config_fs_account_options = { show_secrets : true , decrypt_secret_key : true } ;
2525
26+ const quoted_type = Object . freeze ( {
27+ SPACE_ONLY : "s" , // space only
28+ QUOTE_SPACE : "qs" , // quote then space
29+ SPACE_QUOTE : "sq" , // space then quote
30+ NONE : "none" // none
31+ } ) ;
32+
2633// eslint-disable-next-line max-lines-per-function
2734describe ( 'manage nsfs cli account flow' , ( ) => {
2835 describe ( 'cli create account' , ( ) => {
@@ -108,7 +115,7 @@ describe('manage nsfs cli account flow', () => {
108115 const account_options = { config_root, name, uid, gid} ; // will add new_buckets_path with leading space later
109116 const action = ACTIONS . ADD ;
110117 const command = create_command ( type , action , account_options ) ;
111- const res = await exec_manage_cli_add_leading_space_option ( command , 'new_buckets_path' , new_buckets_path , 's' ) ; // only space
118+ const res = await exec_manage_cli_add_leading_space_option ( command , 'new_buckets_path' , new_buckets_path , quoted_type . SPACE_ONLY ) ; // only space
112119 expect ( JSON . parse ( res . stdout ) . error . code ) . toBe ( ManageCLIError . InvalidArgument . code ) ;
113120 } ) ;
114121
@@ -117,7 +124,7 @@ describe('manage nsfs cli account flow', () => {
117124 const account_options = { config_root, name, uid, gid} ; // will add quoted new_buckets_path with leading space later
118125 const action = ACTIONS . ADD ;
119126 const command = create_command ( type , action , account_options ) ;
120- const res = await exec_manage_cli_add_leading_space_option ( command , 'new_buckets_path' , new_buckets_path , 'sq' ) ; // space then quote
127+ const res = await exec_manage_cli_add_leading_space_option ( command , 'new_buckets_path' , new_buckets_path , quoted_type . SPACE_QUOTE ) ; // space then quote
121128 expect ( JSON . parse ( res . stdout ) . error . code ) . toBe ( ManageCLIError . InvalidArgument . code ) ;
122129 } ) ;
123130
@@ -126,7 +133,7 @@ describe('manage nsfs cli account flow', () => {
126133 const account_options = { config_root, name, uid, gid} ; // will add new_buckets_path with quoted leading space later
127134 const action = ACTIONS . ADD ;
128135 const command = create_command ( type , action , account_options ) ;
129- const res = await exec_manage_cli_add_leading_space_option ( command , 'new_buckets_path' , new_buckets_path , 'qs' ) ; // quote then space
136+ const res = await exec_manage_cli_add_leading_space_option ( command , 'new_buckets_path' , new_buckets_path , quoted_type . QUOTE_SPACE ) ; // quote then space
130137 expect ( JSON . parse ( res . stdout ) . error . code ) . toBe ( ManageCLIError . InvalidAccountNewBucketsPath . code ) ;
131138 } ) ;
132139
@@ -2250,19 +2257,36 @@ async function exec_manage_cli_add_empty_option(command, option) {
22502257 * @param {string } command
22512258 * @param {string } option
22522259 * @param {string } value
2253- * @param {string } quoted
2260+ * @param {"s" | "qs" | "sq" | "none" } quoted
2261+ *
2262+ * @examples
2263+ * - await exec_manage_cli_add_leading_space_option("cli_command", "flag", "val", quoted_type.SPACE_ONLY);
2264+ * // cli_command --flag= val (Space before value)
2265+ *
2266+ * - await exec_manage_cli_add_leading_space_option("cli_command", "flag", "val", quoted_type.QUOTE_SPACE);
2267+ * // cli_command --flag=" val" (quote then space)
2268+ *
2269+ * - await exec_manage_cli_add_leading_space_option("cli_command", "flag", "val", quoted_type.SPACE_QUOTE);
2270+ * // cli_command --flag= "val" (space then quote)
2271+ *
2272+ * - await exec_manage_cli_add_leading_space_option("cli_command", "flag", "val", quoted_type.NONE);
2273+ * // cli_command --flag=val (No special formatting)
22542274 */
22552275async function exec_manage_cli_add_leading_space_option ( command , option , value , quoted ) {
22562276 let changed_command ;
22572277
2258- if ( quoted === 's' ) { // only space
2259- changed_command = command + ` --${ option } = ${ value } ` ;
2260- } else if ( quoted === 'qs' ) { // quote then space
2261- changed_command = command + ` --${ option } =" ${ value } "` ;
2262- } else if ( quoted === 'sq' ) { // space then quote
2263- changed_command = command + ` --${ option } = "${ value } "` ;
2264- } else {
2265- changed_command = command + ` --${ option } =${ value } ` ;
2278+ switch ( quoted ) {
2279+ case quoted_type . SPACE_ONLY :
2280+ changed_command = `${ command } --${ option } = ${ value } ` ;
2281+ break ;
2282+ case quoted_type . QUOTE_SPACE :
2283+ changed_command = `${ command } --${ option } =" ${ value } "` ;
2284+ break ;
2285+ case quoted_type . SPACE_QUOTE :
2286+ changed_command = `${ command } --${ option } = "${ value } "` ;
2287+ break ;
2288+ default :
2289+ changed_command = `${ command } --${ option } =${ value } ` ;
22662290 }
22672291
22682292 let res ;
0 commit comments