online-go / gtp2ogs

GTP Wrapper to allow bots to interface with the Online-Go.com Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FeatReq] add an option to use a config file instead of writing all args in CLI

PabloLION opened this issue · comments

Context

As current options can only be inputed as CLI args and the number of options seems to grow,

In gtp2ogs, options need to be inputted as command-line arguments.
The number of options (and of bot arguments) is free, use the ones you want.
Origin: https://github.com/online-go/gtp2ogs/blob/devel/docs/OPTIONS-LIST.md

Adding a file to store it can be convenient for

  1. fist-time setup
  2. TS typing
  3. profile different default config (like a katago_config.ts for katago users)
  4. switching between configs
  5. handling space character ( ) in username

Suggestion

We can use either dot-env, a json file, or a TS/JS file to store all the configs (like ESLint Config). I'd prefer to first support TS file to give user a clue without adding JSON-Schema.

The file would be like

interface OGS-Config {
beta: boolean;
host: string;
port: number;
apiKey: string;
maxconnectedgames?: number;
debug?: boolean;
// ...
}

export default const config = {
host: "online-go.com",
port: 443,
beta: false,
apiKey: "XXX_SOME_API_KEY_XXX"
}

To adopt this config we need to

  1. add a --configFile path/to/config.ts or use a default path.
  2. update the function updateFromArgv
    export function updateFromArgv(argv) {

Side-effect

  1. more readability for updateFromArgv
  2. easier type-checking and more ts adoption
  3. more structural config
  4. we can have a constant DEFAULT/CONFIG/BASE_CONFIG and split the default/suggested config from building a customised config.

Alternative

Create an executable run.sh in repo root like below (sample args from tutorial-3A5

node ~/gtp2ogs-node/node_modules/gtp2ogs/gtp2ogs.js \
--beta \
--apikey 53e4288597ab04c591dffikz4se8u6v1y2z8tty7 \
--username meta--金毛测试-20b \
--debug \
--persist \
--noclock \
-- \
/home/amd2020/PhoenixGo/bazel-bin/mcts/mcts_main \
--gtp \
--config_path=/home/amd2020/PhoenixGo/etc/mcts_1gpu.conf

Having proper config support would be great, and a great way to clean up the huge amount of cli options that were created and make that a bit more organized and easier to manage.

I'd imagine we could get a lot of good mileage from https://www.npmjs.com/package/config , though I'd be curious to know how including a .ts file as a configuration file would work too. Would that mean bundling the entire typescript compiler and dynamically compiling then loading that file? That seems like it might be a bit heavy for the purpose, but I'm open to exploring it.

I didn't think about it. We'd have to compile it with TS so it would only work when users willing to touch the source code like me.. Maybe a JSON schema is not avoidable if we want the auto-complete function. And the config you said seems nice!

As for the alternative, I don't know if it's in your (@anoek) big picture, is to make a simple GUI like a locally hosted webpage for the config. the setup was quite complicated by my experience.

commented

Lets not get carried away with mixing ts types with config documentation. One is for programmers to check if there code is correct, and uses tooling. The other is for end users that generally dont use tooling, so you would have to document this stuff yourself.

I did a quick writeup to add the config module to gtp2ogs. Fairly straightforwards, but i also ran into some caveats. The config module seems to load the config regardless of calling the config methods, thus my fork is now stuck with a "WARNING: No configurations found in configuration directory:" for non-config users. I was also unable to read all config settings from the root object, would need to dig into the config package to find out if that's something they support. For now i've decided to wrap all config settings in a config root object. Also documentation is still lacking.

My (for now unfished) code is here:

https://github.com/online-go/gtp2ogs/compare/devel...Dorus:gtp2ogs:config-file?expand=1

commented

handling space character ( ) in username

I'm pretty sure this is already supported. Don't forget to put the name in quotes.