Skip to content

Commit

Permalink
release 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kapodes committed Mar 16, 2021
1 parent a604c3c commit c635c88
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.microconfig.server.common.HttpException
import io.microconfig.server.common.ssl.defaultTrust
import io.microconfig.server.common.ssl.rootCa
import io.microconfig.server.common.ssl.trustAll
import java.lang.System.getenv
import java.time.Duration
import javax.net.ssl.SSLContext

Expand All @@ -21,8 +22,8 @@ abstract class Command(val args: Array<String>) {
abstract fun execute(): Int

fun component(message: String): String {
if (args.size < 2) throw CliException(message, 3)
return args[1]
return if (args.size > 1) args[1]
else getenv()["MC_SERVICE"] ?: throw CliException(message, 3)
}

fun configs(component: String, type: String? = null): List<ServiceConfigRaw> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package io.microconfig.cli.commands
import io.microconfig.cli.CliException

val errorMessage = """
Usage: microctl [command] [component] [flags]
Usage: microctl [command] [service] [flags]
No command provided.
Supported commands are [show, save, version, help]
""".trimIndent()

fun command(args: Array<String>): Command {
if (args.isEmpty()) throw CliException(errorMessage, 1)
val cmd = System.getenv()["MC_CMD"]
if (args.isEmpty() && cmd == null) throw CliException(errorMessage, 1)

return when (val command = args[0]) {
return when (val command = args.firstOrNull() ?: cmd) {
"show" -> ShowCommand(args)
"save" -> SaveCommand(args)
"version" -> VersionCommand(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package io.microconfig.cli.commands

class HelpCommand(args: Array<String>) : Command(args) {
private val message = """
Usage: microctl [command] [component] [flags]
Usage: microctl [command] [service] [flags]
Commands:
show: fetch config and show it in console
save: fetch config and save it to disk
show: fetch config and show it in console (MC_CMD=show)
save: fetch config and save it to disk (MC_CMD=save)
version: show cli version
help: show this message
Service:
Generate configs for this service name (MC_SERVICE)
Common Flags:
--ref [master]: git branch or tag to use, by default master
--timeout [10]: server calls timeout in seconds, by default 10
--server [url]: server url (or MCS_ADDRESS env variable), by default [http://localhost:8080]
--skip-tls: skip server tls certificate verification
--tls-root-ca [path]: expected Root CA certificate
--ref [master]: git branch or tag to use, by default master (MC_REF)
--timeout [10]: server calls timeout in seconds, by default 10 (MC_TIMEOUT)
--server [url]: server url, by default [http://localhost:8080] (MC_ADDRESS)
--skip-tls: skip server tls certificate verification (MC_SKIP_TLS=true)
--tls-root-ca [path]: expected Root CA certificate (MC_ROOT_CA)
""".trimIndent()

override fun execute(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SaveCommand(args: Array<String>) : Command(args) {

override fun execute(): Int {
val component = component(helpMessage())
val configs = configs(component)
val configs = configs(component, flags.type())
val outDir = createDir(flags.dir() ?: ".")

configs.forEach { save(it, outDir) }
Expand Down Expand Up @@ -52,12 +52,12 @@ class SaveCommand(args: Array<String>) : Command(args) {

private fun helpMessage(): String {
return """
Usage microctl save [component] [flags]
Generates configuration for component and saves it to disk
Usage microctl save [service] [flags]
Generates configuration for service and saves it to disk
Flags:
-e, --env [name]: config environment
-t, --type [name]: config type, all types by default
-d, --dir [path]: output directory, current dir by default
-e, --env [name]: config environment (MC_ENV)
-t, --type [name]: config type, all types by default (MC_TYPE)
-d, --dir [path]: output directory, current dir by default (MC_DIR)
-s, --set [foo=bar]: override values for placeholders and vars
""".trimIndent()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class ShowCommand(args: Array<String>) : Command(args) {

private fun helpMessage(): String {
return """
Usage microctl show [component] [flags]
Generates configuration for component of specified type and outputs it to console
Usage microctl show [service] [flags]
Generates configuration of specified type for service and outputs it to console
Flags:
-e, --env [name]: config environment
-t, --type [name]: config type, 'app' by default
-e, --env [name]: config environment (MC_ENV)
-t, --type [name]: config type, 'app' by default (MC_TYPE)
-s, --set [foo=bar]: override values for placeholders and vars
""".trimIndent()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.microconfig.cli.commands

class VersionCommand(args: Array<String>) : Command(args) {
override fun execute(): Int {
println("Version 0.2.0")
println("Version 0.5.0")
return 0
}
}

0 comments on commit c635c88

Please sign in to comment.