org.springframework.shell.core.Completion Java Examples

The following examples show how to use org.springframework.shell.core.Completion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnumConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public boolean getAllPossibleValues(final List<Completion> completions, 
    final Class<?> requiredType, final String existingData, 
    final String optionContext, final MethodTarget target) {
	Class<Enum> enumClass = (Class<Enum>) requiredType;
	for (Enum enumValue : enumClass.getEnumConstants()) {
		String candidate = enumValue.name();
     // GemFire/gfsh addition - check 'existingData == null'. GfshParser can 
		// pass existingData as null  
     if ("".equals(existingData) || existingData == null
         || candidate.startsWith(existingData)
         || existingData.startsWith(candidate)
         || candidate.toUpperCase().startsWith(existingData.toUpperCase())
         || existingData.toUpperCase().startsWith(candidate.toUpperCase())) {
			completions.add(new Completion(candidate));
		}
	}
	return true;
}
 
Example #2
Source File: EntityNameConverter.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData, String optionContext, MethodTarget target) {
	try {
		String kind = determineKind(optionContext).get();
		switch (kind) {
			case "stream":
				streamOperations().list().forEach(sdr -> completions.add(new Completion(sdr.getName())));
				break;
			case "task":
				taskOperations().list().forEach(tdf -> completions.add(new Completion(tdf.getName())));
				break;
			case "job":
				jobOperations().executionList().forEach(jer -> {if (!"?".equals(jer.getName())) {
					completions.add(new Completion(jer.getName()));
				}});
				break;
			default:
				throw new AssertionError("Unsupported entity kind: " + kind);
		}
	} // Protect from exceptions in non-command code, as it would crash the whole shell
	catch (Exception e) {
	}
	return false;
}
 
Example #3
Source File: DirConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String[] existingData, String context,
    MethodTarget target) {
  String adjustedUserInput = convertUserInputIntoAFullyQualifiedPath((existingData != null) ? existingData[existingData.length - 1]
      : "");

  String directoryData = adjustedUserInput.substring(0,
      adjustedUserInput.lastIndexOf(File.separator) + 1);
  adjustedUserInput = adjustedUserInput.substring(adjustedUserInput
      .lastIndexOf(File.separator) + 1);

  populate(completions, adjustedUserInput,
      ((existingData != null) ? existingData[existingData.length - 1] : ""),
      directoryData);

  return true;
}
 
Example #4
Source File: EnumConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public boolean getAllPossibleValues(final List<Completion> completions, 
    final Class<?> requiredType, final String existingData, 
    final String optionContext, final MethodTarget target) {
	Class<Enum> enumClass = (Class<Enum>) requiredType;
	for (Enum enumValue : enumClass.getEnumConstants()) {
		String candidate = enumValue.name();
     // GemFire/gfsh addition - check 'existingData == null'. GfshParser can 
		// pass existingData as null  
     if ("".equals(existingData) || existingData == null
         || candidate.startsWith(existingData)
         || existingData.startsWith(candidate)
         || candidate.toUpperCase().startsWith(existingData.toUpperCase())
         || existingData.toUpperCase().startsWith(candidate.toUpperCase())) {
			completions.add(new Completion(candidate));
		}
	}
	return true;
}
 
Example #5
Source File: DirConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String[] existingData, String context,
    MethodTarget target) {
  String adjustedUserInput = convertUserInputIntoAFullyQualifiedPath((existingData != null) ? existingData[existingData.length - 1]
      : "");

  String directoryData = adjustedUserInput.substring(0,
      adjustedUserInput.lastIndexOf(File.separator) + 1);
  adjustedUserInput = adjustedUserInput.substring(adjustedUserInput
      .lastIndexOf(File.separator) + 1);

  populate(completions, adjustedUserInput,
      ((existingData != null) ? existingData[existingData.length - 1] : ""),
      directoryData);

  return true;
}
 
Example #6
Source File: DiskStoreNameConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.DISKSTORE_ALL.equals(optionContext)) {
    Set<String> diskStoreNames = getDiskStoreNames();
    
    for (String diskStoreName : diskStoreNames) {
      if (existingData != null) {
        if (diskStoreName.startsWith(existingData)) {
          completions.add(new Completion(diskStoreName));
        }
      } else {
        completions.add(new Completion(diskStoreName));
      }
    }
  }
  
  return !completions.isEmpty();
}
 
Example #7
Source File: DiskStoreNameConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.DISKSTORE_ALL.equals(optionContext)) {
    Set<String> diskStoreNames = getDiskStoreNames();
    
    for (String diskStoreName : diskStoreNames) {
      if (existingData != null) {
        if (diskStoreName.startsWith(existingData)) {
          completions.add(new Completion(diskStoreName));
        }
      } else {
        completions.add(new Completion(diskStoreName));
      }
    }
  }
  
  return !completions.isEmpty();
}
 
Example #8
Source File: GfshParserTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void assertAdvancedCompletionValues(List<Completion> expected,
    List<Completion> actual) {
  // TODO Auto-generated method stub
  assertEquals("Check size", expected.size(), actual.size());
  for (int i = 0; i < expected.size(); i++) {
    assertEquals("Check completion value no." + i+". Expected("+expected.get(i)+") & Actual("+actual.get(i)+").",
        expected.get(i).getValue(), actual.get(i).getValue());
    if (expected.get(i).getFormattedValue() != null) {
      assertEquals("Check completion formatted value no." + i +". Expected("+expected.get(i).getFormattedValue()+") & Actual("+actual.get(i).getFormattedValue()+").", expected
          .get(i).getFormattedValue(), actual.get(i).getFormattedValue());
    }
  }
}
 
Example #9
Source File: DirConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected void populate(final List<Completion> completions,
    final String adjustedUserInput, final String originalUserInput,
    final String directoryData) {
  File directory = new File(directoryData);

  if (!directory.isDirectory()) {
    return;
  }

  for (File file : directory.listFiles()) {
    if (adjustedUserInput == null
        || adjustedUserInput.length() == 0
        || file.getName().toLowerCase()
            .startsWith(adjustedUserInput.toLowerCase())) {

      String completion = "";
      if (directoryData.length() > 0)
        completion += directoryData;
      completion += file.getName();

      completion = convertCompletionBackIntoUserInputStyle(originalUserInput,
          completion);

      if (file.isDirectory()) {
        completions.add(new Completion(completion + File.separator));
      }
    }
  }
}
 
Example #10
Source File: GfshParser.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void modifyCompletionCandidates(
    List<Completion> completionCandidates, String prefix, boolean endsWithValueSeparator,
    String... existingData) {
  List<Completion> temp = new ArrayList<Completion>();
  while (completionCandidates.size() > 0) {
    temp.add(completionCandidates.remove(0));
  }
  for (Completion completion : temp) {
    boolean includeCompletion = true;
    String value = completion.getValue();
    if (existingData != null) {
      for (String string : existingData) {
        if (string != null) {
          // Check whether that value matches any of the
          // existingData
          // If it matches any one of existing data then we do not
          // need to include it in the list of completion
          // candidates
          if (value.equals(string)) {
            includeCompletion = false;
          }
        }
      }
      if (includeCompletion) {
        if (existingData[existingData.length - 1] != null
            && (!value.startsWith(existingData[existingData.length - 1])
                && !endsWithValueSeparator)) {
          includeCompletion = false;
        }
      }
    }
    if (includeCompletion) {
      // Also we only need to check with the last string of
      // existingData
      // whether the completion value starts with it.
      completionCandidates.add(new Completion(prefix + completion.getValue(),
          completion.getValue(), "", 0));
    }
  }
}
 
Example #11
Source File: GfshParser.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private boolean perfectMatch(List<Completion> completionCandidates,
    String... argumentValue) {
  // Here only the last value should match one of the
  // completionCandidates
  if (argumentValue.length > 0) {
    for (Completion completion : completionCandidates) {
      if (completion.getValue().equals(
          argumentValue[argumentValue.length - 1])) {
        return true;
      }
    }
  }
  return false;
}
 
Example #12
Source File: GfshParser.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private void updateCompletionCandidates(
    List<Completion> completionCandidates, String buffer, int position) {
  List<Completion> temp = new ArrayList<Completion>();
  while (completionCandidates.size() > 0) {
    temp.add(completionCandidates.remove(0));
  }
  for (Completion completion : temp) {
    completionCandidates.add(new Completion(buffer.substring(0, position)
        + completion.getValue(), completion.getFormattedValue(), completion
        .getHeading(), completion.getOrder()));
  }
}
 
Example #13
Source File: GfshParser.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Populates a list of completion candidates. See
 * {@link Parser#complete(String, int, List)} for details.
 *
 * @param buffer
 * @param cursor
 * @param completionCandidates
 * @return new cursor position
 */
public int complete(String buffer, int cursor,
    List<String> completionCandidates) {
  final List<Completion> candidates = new ArrayList<Completion>();
  final int result = completeAdvanced(buffer, cursor, candidates);
  for (final Completion completion : candidates) {
    completionCandidates.add(completion.getValue());
  }
  return result;
}
 
Example #14
Source File: LocatorIdNameConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.LOCATOR_MEMBER_IDNAME.equals(optionContext)) {
    Set<String> locatorIdsAndNames = getLocatorIdAndNames();

    for (String string : locatorIdsAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #15
Source File: ClusterMemberIdNameConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.ALL_MEMBER_IDNAME.equals(optionContext)) {
    Set<String> memberIdAndNames = getMemberIdAndNames();

    for (String string : memberIdAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #16
Source File: QualifiedApplicationNameConverter.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData,
		String optionContext, MethodTarget target) {
	for (AppRegistrationResource app : dataFlowShell.getDataFlowOperations().appRegistryOperations().list()) {
		String value = app.getType() + ":" + app.getName();
		completions.add(new Completion(value, app.getName(), pretty(app.getType()), 0));
	}
	return true;

}
 
Example #17
Source File: GatewayReceiverIdsConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.GATEWAY_RECEIVER_ID.equals(optionContext)) {
    Set<String> gatewaySenderIds = getGatewayRecieverIds();

    for (String gatewaySenderId : gatewaySenderIds) {
      completions.add(new Completion(gatewaySenderId));
    }
  }

  return !completions.isEmpty();
}
 
Example #18
Source File: LocatorDiscoveryConfigConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.LOCATOR_DISCOVERY_CONFIG.equals(optionContext)) {
    Set<String> locatorIdsAndNames = getLocatorIdAndNames();

    for (String string : locatorIdsAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #19
Source File: GatewaySenderIdConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.GATEWAY_SENDER_ID.equals(optionContext)) {
    Set<String> gatewaySenderIds = getGatewaySenderIds();
    
    for (String gatewaySenderId : gatewaySenderIds) {
      completions.add(new Completion(gatewaySenderId));
    }
  }
  
  return !completions.isEmpty();
}
 
Example #20
Source File: HintTopicConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.HINTTOPIC.equals(optionContext)) {
    CommandManager commandManager = CommandManager.getExisting();
    if (commandManager != null) {
      Set<String> topicNames = commandManager.getTopicNames();
      
      for (String topicName : topicNames) {
        if (existingData != null && !existingData.isEmpty()) {
          if (topicName.startsWith(existingData)) { // match exact case
            completions.add(new Completion(topicName));
          } else if (topicName.toLowerCase().startsWith(existingData.toLowerCase())) {  // match case insensitive
            String completionStr = existingData + topicName.substring(existingData.length());
            
            completions.add(new Completion(completionStr));
          }
        } else {
          completions.add(new Completion(topicName));
        }
      }
    }
  }

  return !completions.isEmpty();
}
 
Example #21
Source File: LogLevelConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  completions.addAll(logLevels);
  return !completions.isEmpty();
}
 
Example #22
Source File: LogLevelConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public LogLevelConverter() {
  logLevels = new LinkedHashSet<Completion>();
  int[] alllevels = LogWriterImpl.allLevels;
  for (int level : alllevels) {
    logLevels.add(new Completion(LogWriterImpl.levelToString(level)));
  }
}
 
Example #23
Source File: MemberIdNameConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.MEMBERIDNAME.equals(optionContext)) {
    Set<String> memberIdAndNames = getMemberIdAndNames();

    for (String string : memberIdAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #24
Source File: ConnectionEndpointConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (ConnectionEndpoint.JMXMANAGER_OPTION_CONTEXT.equals(optionContext)) {
    completions.add(new Completion(DEFAULT_JMX_ENDPOINTS));
  } else if (ConnectionEndpoint.LOCATOR_OPTION_CONTEXT.equals(optionContext)) {
    completions.add(new Completion(DEFAULT_LOCATOR_ENDPOINTS));
  }
  
  return completions.size() > 0;
}
 
Example #25
Source File: IndexTypeConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  
  if (String.class.equals(targetType) && ConverterHint.INDEX_TYPE.equals(optionContext)) {
    completions.add(new Completion("range"));
    completions.add(new Completion("key"));
    completions.add(new Completion("hash"));
  }
  return !completions.isEmpty();
}
 
Example #26
Source File: RegionPathConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.REGIONPATH.equals(optionContext)) {
    Set<String> regionPathSet = getAllRegionPaths();
    Gfsh gfsh = Gfsh.getCurrentInstance();
    String currentContextPath = "";
    if (gfsh != null) {
      currentContextPath = gfsh.getEnvProperty(Gfsh.ENV_APP_CONTEXT_PATH);
      if (currentContextPath != null && !com.gemstone.gemfire.management.internal.cli.converters.RegionPathConverter.DEFAULT_APP_CONTEXT_PATH.equals(currentContextPath)) {
        regionPathSet.remove(currentContextPath);
        regionPathSet.add(com.gemstone.gemfire.management.internal.cli.converters.RegionPathConverter.DEFAULT_APP_CONTEXT_PATH);
      }
    }

    for (String regionPath : regionPathSet) {
      if (existingData != null) {
        if (regionPath.startsWith(existingData)) {
          completions.add(new Completion(regionPath));
        }
      } else {
        completions.add(new Completion(regionPath));
      }
    }
  }

  return !completions.isEmpty();
}
 
Example #27
Source File: CompletionConverter.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData,
		String optionContext, MethodTarget target) {
	String start = (existingData.startsWith("'") || existingData.startsWith("\"")) ? existingData.substring(1)
			: existingData;

	try {
		int successiveInvocations = determineNumberOfInvocations(optionContext);
		String kind = completionKind(optionContext);
		CompletionProposalsResource candidates;
		switch (kind) {
		case "stream":
			candidates = completionOperations().streamCompletions(start, successiveInvocations);
			break;
		case "task":
			candidates = completionOperations().taskCompletions(start, successiveInvocations);
			break;
		default:
			throw new IllegalArgumentException("Unsupported completion kind: " + kind);
		}
		for (CompletionProposalsResource.Proposal candidate : candidates.getProposals()) {
			completions.add(new Completion(candidate.getText()));
		}
		return false;
	}
	// Protect from exception in non-command code
	catch (Exception e) {
		return false;
	}
}
 
Example #28
Source File: QualifiedApplicationNameConverter.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData,
		String optionContext, MethodTarget target) {
	for (AppRegistrationResource app : dataFlowShell.getDataFlowOperations().appRegistryOperations().list()) {
		String value = app.getType() + ":" + app.getName();
		completions.add(new Completion(value, app.getName(), pretty(app.getType()), 0));
	}
	return true;

}
 
Example #29
Source File: GfshParserTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void assertAdvancedCompletionValues(List<Completion> expected,
    List<Completion> actual) {
  // TODO Auto-generated method stub
  assertEquals("Check size", expected.size(), actual.size());
  for (int i = 0; i < expected.size(); i++) {
    assertEquals("Check completion value no." + i+". Expected("+expected.get(i)+") & Actual("+actual.get(i)+").",
        expected.get(i).getValue(), actual.get(i).getValue());
    if (expected.get(i).getFormattedValue() != null) {
      assertEquals("Check completion formatted value no." + i +". Expected("+expected.get(i).getFormattedValue()+") & Actual("+actual.get(i).getFormattedValue()+").", expected
          .get(i).getFormattedValue(), actual.get(i).getFormattedValue());
    }
  }
}
 
Example #30
Source File: GfshParser.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void modifyCompletionCandidates(
    List<Completion> completionCandidates, String prefix, boolean endsWithValueSeparator,
    String... existingData) {
  List<Completion> temp = new ArrayList<Completion>();
  while (completionCandidates.size() > 0) {
    temp.add(completionCandidates.remove(0));
  }
  for (Completion completion : temp) {
    boolean includeCompletion = true;
    String value = completion.getValue();
    if (existingData != null) {
      for (String string : existingData) {
        if (string != null) {
          // Check whether that value matches any of the
          // existingData
          // If it matches any one of existing data then we do not
          // need to include it in the list of completion
          // candidates
          if (value.equals(string)) {
            includeCompletion = false;
          }
        }
      }
      if (includeCompletion) {
        if (existingData[existingData.length - 1] != null
            && (!value.startsWith(existingData[existingData.length - 1])
                && !endsWithValueSeparator)) {
          includeCompletion = false;
        }
      }
    }
    if (includeCompletion) {
      // Also we only need to check with the last string of
      // existingData
      // whether the completion value starts with it.
      completionCandidates.add(new Completion(prefix + completion.getValue(),
          completion.getValue(), "", 0));
    }
  }
}