class ViewStatusOption {

  public static ViewStatusOption getViewStatusReporterOption(final CommandLine commandLine, final ToolContext toolContext) {
    ArgumentChecker.notNull(commandLine, "commandLine");
    ArgumentChecker.notNull(toolContext, "toolContext");
    
    String portfolioName = trimToNull(commandLine.getOptionValue(PORTFOLIO_NAME_OPT));
    String userOption = trimToNull(commandLine.getOptionValue(USER_OPT));
    UserPrincipal user = null;
    if (userOption == null) {
      user = DEFAULT_USER;
    } else {
      Matcher matcher = USER_OR_HISTORICAL_PATTERN.matcher(userOption);
      if (matcher.matches()) {
        String username = matcher.group(1);
        String ipaddress = matcher.group(2);
        user = new UserPrincipal(username, ipaddress);
      } else {
        throw new OpenGammaRuntimeException("Given user option [" + userOption + "] does not match expected format username/ipaddress");
      }
    }
    
    String format = defaultString(trimToNull(commandLine.getOptionValue(FORMAT_TYPE_OPT)), DEFAULT_FORMAT);
    String aggregationOption = trimToNull(commandLine.getOptionValue(AGGREGATION_TYPE_OPT));
    AggregateType aggregateType = null;
    if (aggregationOption != null) {
      aggregateType = AggregateType.of(aggregationOption);
    } else {
      aggregateType = AggregateType.NO_AGGREGATION;
    }
    
    String outputOption = trimToNull(commandLine.getOptionValue(OUTPUT_OPT));
    File outputFile = null;
    if (outputOption != null) {
      outputFile = new File(outputOption);
    } else {
      outputFile = new File(DEFAULT_OUTPUT_NAME + "." + ResultFormat.of(format).getExtension());
    }
    
    MarketDataSpecification marketDataSpec = getMarketDataSpecification(commandLine, toolContext);
    return new ViewStatusOption(portfolioName, format, user, aggregateType, outputFile, marketDataSpec);
  }

  private  ViewStatusOption(final String portfolioName, final String formatOption, final UserPrincipal user, 
      final AggregateType aggregateType, final File outputFile, final MarketDataSpecification marketDataSpecification);

}