Add basic autocomplete support

ca-store now takes a --completion argument to output completions
to standard output. These are to be used for completion scripts,
in future commits.

Before the 1.0.0 release we need to either:
1) Work out how to get bash et al to accept these completions
   without mangling them
2) Get optparse-applicative to handle the command parsing entirely
   and forgo the Moore machine approach
This commit is contained in:
hylodon 2025-09-22 13:43:57 +01:00
parent 6d4bc78475
commit 1849baa588
9 changed files with 181 additions and 37 deletions

View file

@ -1,8 +1,9 @@
module Main(main) where
import CAStore.Command (runCommand)
import CAStore.Command.Autocomplete (generateAutocompletions)
import CAStore.Config (finalConfig)
import CAStore.Program (Program, runProgram, getCommand)
import CAStore.Program (Program, runProgram, getCommand, getAutocomplete)
import CAStore.Program.IO.Text (err)
import CAStore.Program.Storage (initialise)
@ -12,4 +13,6 @@ main = finalConfig >>= flip runProgram defaultProgram
defaultProgram :: Program ()
defaultProgram = do
initialise
getCommand >>= either err runCommand
getAutocomplete >>= \case
True -> generateAutocompletions
False -> getCommand >>= either err runCommand