code: function refineArguments(args, watchMode, commandSource) {
      const refinedArgs = [];
      let hasOptionalWatchArg = false;
      let grepString = null;
      for (let i=0; i<args.length; ++i) {
          let arg = args[i];
          if (arg === '[--watch') {
              hasOptionalWatchArg = true;
              if (watchMode) {
                  refinedArgs.push('--watch');
                  if (i + 1 >= args.length)
                      throw new Error (`Missing grepString in the following command: "${commandSource}"`);
                  grepString = args[i + 1];
              }
              if (i + 2 >= args.length || args[i + 2] !== ']')
                  throw new Error (`Missing ']' in the following command: ${commandSource}`);
              i += 2;
          } else {
              refinedArgs.push(arg);
          }
      };
      return {
          refinedArgs,
          grepString: grepString,
          useWatch: hasOptionalWatchArg && watchMode
      };
  }
docs: Takes an array of arguments and removes "[--watch ...]" if not watchMode. Otherwise,
  includes "--watch".
  
  @returns {{
  refinedArgs: string,
  grepString: string,
  useWatch: boolean
  }} Returns the refined arguments together with the grepString to watch for in case useWatch is true.