Repository: apple/pkl
File: pkl-cli/src/main/kotlin/org/pkl/cli/commands/TestCommand.kt (Kotlin)

Code before:
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.pkl.cli.commands

import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.convert
import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.groups.provideDelegate
import com.github.ajalt.clikt.parameters.types.path
import java.net.URI
import org.pkl.cli.CliTestRunner
import org.pkl.commons.cli.commands.BaseCommand
import org.pkl.commons.cli.commands.BaseOptions
import org.pkl.commons.cli.commands.ProjectOptions
import org.pkl.commons.cli.commands.TestOptions

class TestCommand : BaseCommand(name = "test", helpLink = helpLink) {
  override val helpString = "Run tests within the given module(s)"

  val modules: List<URI> by
    argument(name = "modules", help = "Module paths or URIs to evaluate.")
      .path()
      .convert { BaseOptions.parseModuleName(it.toString()) }
      .multiple()

  private val projectOptions by ProjectOptions()

  private val testOptions by TestOptions()

  override fun run() {
    CliTestRunner(
        options = baseOptions.baseOptions(modules, projectOptions),
        testOptions = testOptions.cliTestOptions,
      )
      .run()
  }
}


Review comment (suggestion):
Using `.path()` tells Clikt to parse this into a `java.nio.file.Path`, which can throw in some cases, and also doesn't round-trip back to string in other cases (`foo://bar/baz` turns into `foo:/bar/baz`)

I think we should just use completionCandidates here.

```kt
    argument(
        name = "modules",
        help = "Module paths or URIs to evaluate.",
        completionCandidates = CompletionCandidates.Path,
      )
      .convert { BaseOptions.parseModuleName(it) }
      .multiple()
```

Code after:
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.pkl.cli.commands

import com.github.ajalt.clikt.completion.CompletionCandidates
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.convert
import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.groups.provideDelegate
import java.net.URI
import org.pkl.cli.CliTestRunner
import org.pkl.commons.cli.commands.BaseCommand
import org.pkl.commons.cli.commands.BaseOptions
import org.pkl.commons.cli.commands.ProjectOptions
import org.pkl.commons.cli.commands.TestOptions

class TestCommand : BaseCommand(name = "test", helpLink = helpLink) {
  override val helpString = "Run tests within the given module(s)"

  val modules: List<URI> by
    argument(
        name = "modules",
        help = "Module paths or URIs to evaluate.",
        completionCandidates = CompletionCandidates.Path,
      )
      .convert { BaseOptions.parseModuleName(it) }
      .multiple()

  private val projectOptions by ProjectOptions()

  private val testOptions by TestOptions()

  override fun run() {
    CliTestRunner(
        options = baseOptions.baseOptions(modules, projectOptions),
        testOptions = testOptions.cliTestOptions,
      )
      .run()
  }
}