from kbasic.shell import color, warn
from kbasic.parsing import File, Folder, parse, ensure_path
from os.path import abspath
from sys import argv
def kpaper():
    [_script_path_, *args] = argv
    match args:
        case []: warn('no commands given...')
        case ['init']:
            print(color(f'initializing kpaper project in {abspath('./')}...', 'blue'))
            template = Folder(__file__+'/templates/default')
            print("using template: "+color(template.path, 'blue'))
            for c in template.children: parse(c).copy('./')
        case ['init', str(path)]:
            ensure_path(path)
            print(color(f'initializing kpaper project in {abspath(path)}', 'blue'))
            kpaperDir = File(__file__).parent
            template: Folder = kpaperDir + '/templates/default'
            config_file = File(kpaperDir.path + '/templates/config-template')
            config_file.copy(path+'/.kpaper')
            print(template.children)
            for c in template.children: 
                child = parse(c)
                child.copy(path+'/'+child.name)
