Skip to content

Commit

Permalink
Rename NoRunCliktCommand to NoOpCliktCommand (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajalt authored Feb 21, 2020
1 parent d407c5e commit e6e3f95
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 41 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
### Fixed
- `file()` and `path()` conversions will now properly expand leading `~` in paths to the home directory for `mustExist`, `canBeFile`, and `canBeDir` checks. The property value is unchanged, and can still begin with a `~`. ([#131](https://github.com/ajalt/clikt/issues/79))

### Changed
- `NoRunCliktCommand` was renamed to `NoOpCliktCommand`. The existing class is deprecated. ([#130](https://github.com/ajalt/clikt/issues/130))

## [2.5.0-beta1] - 2020-02-13
### Added
- Clikt is now available as a Kotlin Multiplatform Project, supporting JVM, NodeJS, and native Windows, Linux, and macOS.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.ajalt.clikt.core

/**
* A [CliktCommand] that has a default implementation of [CliktCommand.run] that is a no-op.
*/
open class NoOpCliktCommand(
help: String = "",
epilog: String = "",
name: String? = null,
invokeWithoutSubcommand: Boolean = false,
printHelpOnEmptyArgs: Boolean = false,
helpTags: Map<String, String> = emptyMap(),
autoCompleteEnvvar: String? = ""
) : CliktCommand(help, epilog, name, invokeWithoutSubcommand, printHelpOnEmptyArgs, helpTags, autoCompleteEnvvar) {
override fun run() = Unit
}

@Deprecated(
"This class has been renamed to NoOpCliktCommand",
ReplaceWith("NoOpCliktCommand(help, epilog, name, invokeWithoutSubcommand, printHelpOnEmptyArgs, helpTags, autoCompleteEnvvar)")
)
open class NoRunCliktCommand(
help: String = "",
epilog: String = "",
name: String? = null,
invokeWithoutSubcommand: Boolean = false,
printHelpOnEmptyArgs: Boolean = false,
helpTags: Map<String, String> = emptyMap(),
autoCompleteEnvvar: String? = ""
) : CliktCommand(help, epilog, name, invokeWithoutSubcommand, printHelpOnEmptyArgs, helpTags, autoCompleteEnvvar) {
override fun run() = Unit
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CliktCommandTest {
row("```\n foo bar", "foo bar"),
row("```foo\nbar", "foo")
) { help, expected ->
class C : NoRunCliktCommand(help = help) {
class C : NoOpCliktCommand(help = help) {
val sh = shortHelp()
}
C().sh shouldBe expected
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.ajalt.clikt.output

import com.github.ajalt.clikt.core.NoRunCliktCommand
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.context
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.output.HelpFormatter.ParameterHelp
Expand Down Expand Up @@ -497,7 +497,7 @@ class CliktHelpFormatterTest {
val groupBaz by option(help = "this group doesn't have help").required()
}

class C : NoRunCliktCommand(name = "program",
class C : NoOpCliktCommand(name = "program",
help = """
This is a program.
Expand Down Expand Up @@ -536,14 +536,14 @@ class CliktHelpFormatterTest {
}
}

class Sub : NoRunCliktCommand(help = """
class Sub : NoOpCliktCommand(help = """
a subcommand
with extra help
""",
helpTags = mapOf("deprecated" to ""))

class Sub2 : NoRunCliktCommand(help = "another command")
class Sub2 : NoOpCliktCommand(help = "another command")

val c = C()
.versionOption("1.0")
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and returns a map of aliases to the tokens that they alias to.
To implement git-style aliases:

```kotlin tab="Example"
class Repo : NoRunCliktCommand() {
class Repo : NoOpCliktCommand() {
// You could load the aliases from a config file etc.
override fun aliases(): Map<String, List<String>> = mapOf(
"ci" to listOf("commit"),
Expand Down
4 changes: 2 additions & 2 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ For example, you can change the default help message for the `--help`
option. These definitions are equivalent:

```kotlin
class Cli : NoRunCliktCommand() {
class Cli : NoOpCliktCommand() {
init {
context { helpOptionMessage = "print the help" }
}
Expand All @@ -246,7 +246,7 @@ class Cli : NoRunCliktCommand() {
and

```kotlin
class Cli : NoRunCliktCommand()
class Cli : NoOpCliktCommand()
fun main(args: Array<String>) = Cli()
.context { helpOptionMessage = "print the help" }
.main(args)
Expand Down
16 changes: 8 additions & 8 deletions docs/documenting.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ removed. All whitespace and newlines in the paragraph will be preserved, and wil


```kotlin tab="Example"
class Tool : NoRunCliktCommand(help = """This is my command.
class Tool : NoOpCliktCommand(help = """This is my command.
This paragraph will be wrapped, but the following list will not:
Expand Down Expand Up @@ -91,15 +91,15 @@ Subcommands are listed in the help page based on their [name][customizing-comman
They have a short help string which is the first line of their help.

```kotlin tab="Example"
class Tool : NoRunCliktCommand()
class Tool : NoOpCliktCommand()

class Execute : NoRunCliktCommand(help = """
class Execute : NoOpCliktCommand(help = """
Execute the command.
The command will be executed.
""")

class Abort : NoRunCliktCommand(help="Kill any running commands.")
class Abort : NoOpCliktCommand(help="Kill any running commands.")
```

```text tab="Usage"
Expand All @@ -126,7 +126,7 @@ You can change the help option's name and help message on the
[command's context][customizing-context]:

```kotlin tab="Example"
class Tool : NoRunCliktCommand() {
class Tool : NoOpCliktCommand() {
init {
context {
helpOptionNames = setOf("/help")
Expand Down Expand Up @@ -155,7 +155,7 @@ default value will be shown. You can show a different value by passing the value
the `defaultForHelp` parameter of [`default`][default].

```kotlin tab="Example"
class Tool : NoRunCliktCommand() {
class Tool : NoOpCliktCommand() {
init {
context { helpFormatter = CliktHelpFormatter(showDefaultValues = true) }
}
Expand Down Expand Up @@ -186,7 +186,7 @@ that an option is required.
You can pass a character to the `requiredOptionMarker` argument of the `CliktHelpFormatter`.

```kotlin tab="Example"
class Tool : NoRunCliktCommand() {
class Tool : NoOpCliktCommand() {
init {
context { helpFormatter = CliktHelpFormatter(requiredOptionMarker = "*") }
}
Expand Down Expand Up @@ -244,7 +244,7 @@ class UserOptions : OptionGroup(name = "User Options", help = "Options controlli
val age by option(help = "user age").int()
}

class Tool : NoRunCliktCommand() {
class Tool : NoOpCliktCommand() {
val userOptions by UserOptions()
}
```
Expand Down
7 changes: 3 additions & 4 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ function on a command directly, either in an `init` block, or on a command insta
These definitions are equivalent:

```kotlin
class Cli : NoRunCliktCommand() {
class Cli : NoOpCliktCommand() {
init {
versionOption("1.0")
}
Expand All @@ -629,7 +629,7 @@ fun main(args: Array<String>) = Cli().main(args)
and

```kotlin
class Cli : NoRunCliktCommand()
class Cli : NoOpCliktCommand()
fun main(args: Array<String>) = Cli().versionOption("1.0").main(args)
```

Expand All @@ -653,13 +653,12 @@ of printing the message.
You can define your own version option like this:

```kotlin
class Cli : CliktCommand() {
class Cli : NoOpCliktCommand() {
init {
registerOption(EagerOption("--version") {
throw PrintMessage("$commandName version 1.0")
})
}
// ...
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.ajalt.clikt.samples.aliases

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.NoRunCliktCommand
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.output.TermUi
import com.github.ajalt.clikt.parameters.options.multiple
Expand All @@ -13,7 +13,7 @@ import java.io.File
* @param configFile A config file containing aliases, one per line, in the form `token = alias`. Aliases can
* have multiple tokens (e.g. `cm = commit -m`).
*/
class AliasedCli(private val configFile: File) : NoRunCliktCommand(
class AliasedCli(private val configFile: File) : NoOpCliktCommand(
help = "An example that supports aliased subcommands") {
override fun aliases(): Map<String, List<String>> {
return configFile.readLines().map { it.split("=", limit = 2) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.ajalt.clikt.samples.ansicolors

import com.github.ajalt.clikt.core.NoRunCliktCommand
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.context
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.output.CliktHelpFormatter
Expand All @@ -23,7 +23,7 @@ class ColorHelpFormatter : CliktHelpFormatter() {
override fun optionMetavar(option: HelpFormatter.ParameterHelp.Option) = tc.green(super.optionMetavar(option))
}

class Cli : NoRunCliktCommand(help = "An example of a custom help formatter that uses ansi colors") {
class Cli : NoOpCliktCommand(help = "An example of a custom help formatter that uses ansi colors") {
init {
context { helpFormatter = ColorHelpFormatter() }
}
Expand All @@ -33,6 +33,6 @@ class Cli : NoRunCliktCommand(help = "An example of a custom help formatter that
val files by argument(help = "files to input").multiple()
}

class Sub : NoRunCliktCommand(help = "this is a subcommand")
class Sub : NoOpCliktCommand(help = "this is a subcommand")

fun main(args: Array<String>) = Cli().subcommands(Sub()).main(args)

0 comments on commit e6e3f95

Please sign in to comment.