import json
import os
import sys

CONFIG_FILE = os.path.expanduser("~/.slashmark_config.json")

def load_config():
    if os.path.exists(CONFIG_FILE):
        with open(CONFIG_FILE, "r") as f:
            return json.load(f)
    return {}

def save_config(data):
    with open(CONFIG_FILE, "w") as f:
        json.dump(data, f, indent=2)

def main():
    if len(sys.argv) < 2:
        print("Usage: sm-config [set|get] key [value]")
        return

    cmd = sys.argv[1]
    config = load_config()

    if cmd == "set" and len(sys.argv) == 4:
        config[sys.argv[2]] = sys.argv[3]
        save_config(config)
        print("Saved")

    elif cmd == "get" and len(sys.argv) == 3:
        print(config.get(sys.argv[2], "Not found"))

    else:
        print("Invalid usage")

if __name__ == "__main__":
    main()
