Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a read-execute-print-loop prompt for Cmdline #2273

Merged
merged 1 commit into from
Feb 13, 2018

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Feb 4, 2018

Fixes #2161.

Background

CKAN's Cmdline interface executes one command and then exits. Scripts can be written with CKAN, but they require CKAN to be executed once per command, with the cost of parsing registry.json incurred for each command.

Changes

A new ckan prompt command is created that:

  • Prompts the user for commands as input, displaying the CKAN version and the name and game version of the active instance, if any
  • Interprets them as Cmdline commands and subcommands
  • Only parses registry.json once for a given instance across multiple commands, so you don't have to wait several seconds between operations
  • Carries its CommonOptions flags over to the commands it runs (mainly to make a top-level --headless work properly)

Line break added before the install command to simulate having the screen pause for input:

$ ckan.exe prompt
CKAN v1.24.0-PRE2> list

KSP found at C:/Program Files (x86)/Steam/steamapps/common/Kerbal Space Program

KSP Version: 1.3.1.1891

Installed Modules:

- KSPSteamCtrlr autodetected dll
- LoadingTipsPlus V1.5
- ModuleManager 3.0.1
- Steamworks autodetected dll

Legend: -: Up to date. X: Incompatible. ^: Upgradable. ?: Unknown. *: Broken.

CKAN v1.24.0-PRE2: KSP 1.3.1.1891 (Steam)> install astrogator
About to install...

 * Astrogator v0.7.8 (cached)

Continue? [Y/n]


Installing mod "Astrogator v0.7.8"
Updating registry
Commiting filesystem changes
Rescanning GameData
Done!
CKAN v1.24.0-PRE2: KSP 1.3.1.1891 (Steam)> exit

ckan prompt --headless now works kind of like a CKAN scripting language:

$ cat ~/Documents/ckan-script.txt
ksp list
list
repo list
authtoken list
update
upgrade --all

$ ckan prompt --headless < ~/Documents/ckan-script.txt
Name   Version     Default  Path
-----  ----------  -------  ------------------------------------------------------------------
Steam  1.3.1.1891  Yes      C:/Program Files (x86)/Steam/steamapps/common/Kerbal Space Program
Fake2  1.3.1       No       c:/users/user/downloads/fakeksp2
Fake   1.2.2       No       C:/Users/user/Downloads/FakeKSP

KSP found at C:/Program Files (x86)/Steam/steamapps/common/Kerbal Space Program

KSP Version: 1.3.1.1891

Installed Modules:

- KSPSteamCtrlr autodetected dll
- LoadingTipsPlus V1.5
- ModuleManager 3.0.1
- Steamworks autodetected dll

Legend: -: Up to date. X: Incompatible. ^: Upgradable. ?: Unknown. *: Broken.
Listing all known repositories:
  default: 0: https://github.com/KSP-CKAN/CKAN-meta/archive/master.tar.gz
Host            Token
--------------  ------------------------------------
api.github.com  abcdefghijklmnopqrstuvwxyz0123456789
Downloading updates...
Updated information on 802 available modules

Upgrading modules...


Done!

Other changes

  • The command-running code is refactored into an Execute function to make it easier to parse and run commands from other commands. This also allowed us to centralize the DisposeAll calls that each subcommand previously had to handle itself.
  • CompatSubCommand is renamed to Compat for consistency with other subcommands

Not Done Yet

Tab completion as in #888 and #2174 is not implemented. It should be possible to add it to Prompt.cs's input driver. (Or it might be cleaner to do bash completion instead.)

@HebaruSan HebaruSan added Enhancement New features or functionality Cmdline Issues affecting the command line Pull request labels Feb 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmdline Issues affecting the command line Enhancement New features or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants