ObsidianToAnki / Obsidian_to_Anki

Script to add flashcards from text/markdown files to Anki
GNU General Public License v3.0
1.41k stars 125 forks source link

[Feature Request] Add the ability to pass in the configuration file from the command line #595

Open cjappl opened 1 week ago

cjappl commented 1 week ago

(for the record, I'm more than willing to implement this feature myself and put up a PR, I just want to file this to discuss before putting in the work).

Currently, the config file is hard coded to be the one next to the script:

CONFIG_PATH = os.path.expanduser(
    os.path.join(
        os.path.dirname(os.path.realpath(__file__)),
        "obsidian_to_anki_config.ini"
    )
)

It would be nice to be able to move this file to some other directory, where I could back it up in my own git repository alongside my obsidian notes. I would imagine something like

> python obsidian_to_anki.py -R $OBSIDIAN --regex --config_path=$OBSIDIAN/obsidian_to_anki_data.json

This leads to a few questions, if this feature is desirable

  1. What should the flag and shortname be? (I would expect as a user to use --config and -c, but that would mean moving that existing flag to be --edit-config/-e)
  2. Should we configure the directory that both DATA_PATH and CONFIG_PATH live in? We could do two birds with one stone. This would mean that users can't configure the name of their ini and .json file, which could be desirable
CONFIG_PATH = os.path.expanduser(
    os.path.join(
        os.path.dirname(os.path.realpath(__file__)),
        "obsidian_to_anki_config.ini"
    )
)
...

DATA_PATH = os.path.expanduser(
    os.path.join(
        os.path.dirname(os.path.realpath(__file__)),
        "obsidian_to_anki_data.json"
    )
)
# OBSIDIAN_CONFIG_DIR contains both obsidian_to_anki_config.ini and obsidian_to_anki_data.json
python obsidian_to_anki.py -R $OBSIDIAN_NOTES --regex --config_dir=$OBSIDIAN_CONFIG_DIR