#!python

import argparse
import sys

try:
    from kyk.kyk import Kyk
except ImportError:
    from kyk import Kyk


EXAMPLE = """
# kyk config file
#----------------------
# cfg version
version: 1

# optional, if True no minification is performed
debug: False

# optional, if changes are detected we change the unix timestamp in this file
timestamp_file: ./timestamp

# optional, define path that is watched for changes, defaults to current working dir
# watch_path: .

# possible events on which css or js is build, takes everything pyinotify takes
events:
- IN_MODIFY
- IN_MOVE
- IN_MOVED_TO

# js files, if min: is prepended minify first (saved to filename_minified) and then concat to main file (main.min.js)
./test/main.min.js:
- "test/vendor/jquery/jquery-1.11.3.min.js"
- "test/vendor/bootstrap-4.0.0-alpha.2/dist/js/bootstrap.min.js"
- "min:test/local/main.js"

# if a css file is detected it is minified everytime, if a scss file is detected it is compiled first
./test/main.min.css:
- "test/styles.scss"
- "test/style.dev.css"
"""


def main():
    a = argparse.ArgumentParser(description="kyk watchscript, detect changes in sass and configured js files with pyinotify")
    a.add_argument('--yaml', action='store_true', help='print example yaml config for kyk')
    a.add_argument('--debug', action='store_true', help='no minification, only concatenation of files')
    a.add_argument('--oneshot', action='store_true', help='No watchscript just generate everything once, then exti')
    args = vars(a.parse_args())

    if args['yaml']:
        print(EXAMPLE)
        sys.exit(0)

    k = Kyk('.', args['debug'])

    if args['oneshot']:
        k.oneshot()
    else:
        k.watch_forever()


if __name__ == '__main__':
    main()
