#!/usr/bin/env python3
from init import *
import argparse


def get_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description='Change the grub menu configs.')
    parser.add_argument('-s', '--show', type=int, help='1 indicates to show grub menu, 0 is the opposite')
    parser.add_argument('-t', '--timeout', type=int, help='Value of GRUB_TIMEOUT')
    help_str = ('Enable os-prober, this will auto detect then create new grub boot entries. '
                'for example, adding existing Windows system on disk')
    parser.add_argument('-p', '--probe', action='store_true', help=help_str)
    parsed_args = parser.parse_args()
    return parsed_args


if __name__ == '__main__':
    args = get_args()
    print(args)
    ce = ConfigEditor('/etc/default/grub')
    if args.show == 1:
        ce.sub_value('GRUB_TIMEOUT_STYLE', 'show')
    elif args.show == 0:
        ce.sub_value('GRUB_TIMEOUT_STYLE', 'hidden')
    if args.timeout:
        ce.sub_value('GRUB_TIMEOUT', args.timeout)
    if args.probe:
        ce.append('GRUB_DISABLE_OS_PROBER', 'false')
        execute('os-prober')
    execute('update-grub')
    execute('cat /etc/default/grub')
