mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-09 10:19:47 +02:00
Implement profiles
This commit is contained in:
parent
b8544396f8
commit
5935d65c90
11 changed files with 75 additions and 43 deletions
|
@ -401,12 +401,33 @@ public abstract class SOPGPException extends RuntimeException {
|
|||
|
||||
public static final int EXIT_CODE = 89;
|
||||
|
||||
public UnsupportedProfile() {
|
||||
super();
|
||||
private final String subcommand;
|
||||
private final String profile;
|
||||
|
||||
public UnsupportedProfile(String subcommand) {
|
||||
super("Subcommand '" + subcommand + "' does not support any profiles.");
|
||||
this.subcommand = subcommand;
|
||||
this.profile = null;
|
||||
}
|
||||
|
||||
public UnsupportedProfile(String errorMessage) {
|
||||
super(errorMessage);
|
||||
public UnsupportedProfile(String subcommand, String profile) {
|
||||
super("Subcommand '" + subcommand + "' does not support profile '" + profile + "'.");
|
||||
this.subcommand = subcommand;
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public UnsupportedProfile(String errorMsg, UnsupportedProfile e) {
|
||||
super(errorMsg, e);
|
||||
this.subcommand = e.getSubcommand();
|
||||
this.profile = e.getProfile();
|
||||
}
|
||||
|
||||
public String getSubcommand() {
|
||||
return subcommand;
|
||||
}
|
||||
|
||||
public String getProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,8 +6,8 @@ package sop.operation;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import sop.Profile;
|
||||
import sop.Ready;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.util.UTF8Util;
|
||||
|
@ -57,11 +57,21 @@ public interface GenerateKey {
|
|||
return withKeyPassword(UTF8Util.decodeUTF8(password));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass in a profile.
|
||||
*
|
||||
* @param profile profile
|
||||
* @return builder instance
|
||||
*/
|
||||
default GenerateKey profile(Profile profile) {
|
||||
return profile(profile.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass in a profile identifier.
|
||||
*
|
||||
* @param profile profile identifier
|
||||
* @return this
|
||||
* @return builder instance
|
||||
*/
|
||||
GenerateKey profile(String profile);
|
||||
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
package sop.operation;
|
||||
|
||||
import sop.Profile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ListProfiles {
|
||||
|
||||
List<String> ofCommand(String command);
|
||||
|
||||
List<String> global();
|
||||
List<Profile> subcommand(String command);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package sop.testsuite.operation;
|
|||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.Profile;
|
||||
import sop.SOP;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -21,19 +22,11 @@ public class ListProfilesTest extends AbstractSOPTest {
|
|||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void listGlobalProfiles(SOP sop) throws IOException {
|
||||
List<String> profiles = sop.listProfiles()
|
||||
.global();
|
||||
assertFalse(profiles.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void listGenerateKeyProfiles(SOP sop) throws IOException {
|
||||
List<String> profiles = sop.listProfiles()
|
||||
.ofCommand("generate-key");
|
||||
List<Profile> profiles = sop.listProfiles()
|
||||
.subcommand("generate-key");
|
||||
assertFalse(profiles.isEmpty());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue