pgpainless/pgpainless-wot-cli/src/main/kotlin/org/pgpainless/wot/cli/subcommands/IdentifyCmd.kt

36 lines
990 B
Kotlin
Raw Normal View History

2023-06-29 17:49:12 +02:00
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.wot.cli.subcommands
2023-07-11 14:39:37 +02:00
import org.pgpainless.wot.api.IdentifyAPI
2023-06-29 17:49:12 +02:00
import org.pgpainless.wot.cli.WotCLI
2023-07-11 14:39:37 +02:00
import org.pgpainless.wot.network.Fingerprint
2023-06-29 17:49:12 +02:00
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.Parameters
import java.text.SimpleDateFormat
2023-06-29 17:49:12 +02:00
import java.util.concurrent.Callable
@Command(name = "identify")
class IdentifyCmd: Callable<Int> {
@CommandLine.ParentCommand
lateinit var parent: WotCLI
@Parameters(index = "0", description = ["Certificate fingerprint."])
lateinit var fingerprint: String
/**
* Execute the command.
*
* @return exit code
*/
override fun call(): Int {
2023-07-13 16:53:35 +02:00
val result = parent.api.identify(IdentifyAPI.Arguments(Fingerprint(fingerprint)))
2023-07-11 14:39:37 +02:00
2023-07-13 16:53:35 +02:00
print(parent.formatter.format(result))
return if (result.acceptable) 0 else 1
2023-07-11 14:39:37 +02:00
}
2023-06-29 17:49:12 +02:00
}