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AW,QAAQ,KACnB,SAAY,SAAS,MAEzB,OAAU,CACN,KAAQ,MAAM,QAElB,OAAU,CACN,KAAQ,MAAM,QAElB,OAAU,CACN,OAAU,QAAQ,OAClB,QAAW,SAAS,OACpB,QAAW,eAEf,OAAU,CACN,QAAW,SAAS,QAExB,UAAa,CACT,OAAU,QAAQ,UAClB,OAAU,QAAQ,UAClB,QAAW,SAAS,WAExB,KAAQ,QAAQ,KAChB,OAAU,QAAQ,UACf,SAGD,eAAiB,CACnB,MAAS,WACT,OAAU,QAGR,SAAW,CAAC,EAElB,eAAe,UACX,MAAO,KAAY,GAAQ,QAAQ,KAAK,MAAM,GAE9C,SAAU,YAAa,CACnB,MAAM,OAAE,SAAiB,gBAAgB,QAEpC,GACD,OAAO,OAAO,SAAU,gBAG5B,OAAO,OAAO,SAAU,eAC5B,MACI,OAAO,OAAO,SAAU,gBAG5B,OAAO,OAAO,SAAU,CAAE,KAAM,YAAa,SAAU,QAAQ,WAE1D,GAAa,KAAW,WACzB,KAAK,CAAC,GACN,QAAQ,QAGP,EAAK,OAQF,SAAS,GAAS,mBAAmB,SACrC,eAAe,SAAS,GAAU,GAElC,eAAe,SAAS,GAAS,EAAK,IAAK,EAAK,MAAM,IAVtD,YAAa,SAAS,IAAY,SAAS,GAAS,mBAAmB,SACvE,SAAS,GAAS,QAAQ,CAAC,IAE3B,KAAK,CAAE,YACP,QAAQ,OASpB,CAEA","file":"/npm/learnit@1.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/learnit@1.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","#!/usr/bin/env node\n\nconst courses = require('./cli/courses');\nconst modules = require('./cli/modules');\nconst chapters = require('./cli/chapters');\nconst steps = require('./cli/steps');\nconst createCommand = require('./cli/create-command');\nconst deleteCommand = require('./cli/delete-command');\nconst instructor = require('./instructor');\nconst output = require('./output');\nconst { snake, underscore } = require('./cli/utils');\nconst { unrecognized } = require('./common/errors');\nconst general = require('./cli/general');\n\nconst { getBranchConfig } = require('./cli/git-helpers');\nconst { isGitRepo } = require('./common/git-fs');\n\nconst parseArg = (type, str) => {\n    switch (type) {\n        case 'STR': return str;\n        case 'BOOL': return !str || str.toLowerCase() === 'true';\n        case 'STR[]': return str.split(',');\n    }\n};\n\nconst processCommand = ({ command, args }, argv) => {\n    const parsedArgs = {};\n    const allArgs = Object.entries(args);\n    const namedArgs = allArgs.filter(([key, options]) => options.named);\n    const unnamedArgs = allArgs.filter(([key, options]) => !options.named);\n\n    argv.forEach(arg => {\n        if (arg.startsWith('--')) {\n            const argKey = arg.includes('=') ? arg.substr(2, arg.indexOf('=') - 2) : arg.substr(2);\n            const argValue = arg.includes('=') ? arg.substr(arg.indexOf('=') + 1) : '';\n\n            try {\n                const [key, options] = namedArgs.find(([key]) => snake(key) === argKey);\n                parsedArgs[key] = parseArg(options.type, argValue);\n            } catch (e) {\n                unrecognized.arg(argKey);\n            }\n\n        } else if (unnamedArgs.length) {\n            const [key, options] = unnamedArgs.shift();\n            parsedArgs[key] = parseArg(options.type, arg);\n        } else {\n            console.log('Too many unnamed arguments supplied.');\n            process.exit();\n        }\n    });\n\n    allArgs.filter(([key, options]) => !options.optional).forEach(([key]) => {\n        if (!(key in parsedArgs)) {\n            console.log(`Missing required argument '${snake(key)}'.`);\n            process.exit();\n        }\n    });\n\n    return command(parsedArgs);\n};\n\nconst documentation = (first, second, { description, args }) => {\n    console.log(second ? `\\n  ${first} ${second}` : `\\n  ${first}`);\n    console.log(`     - ${description}`);\n\n    for (const arg in args) {\n        const { named, hint, optional, type, description } = args[arg]; \n        let asArg = named ? `--${snake(arg)}${hint ? `=${hint}` : ''}` : underscore(arg);\n        asArg = optional ? `[${asArg}]` : `<${asArg}>`;\n        console.log(`      ${asArg}: (${type}) ${description}`);\n    }\n};\n\nconst help = ({ command, subCommand }) => {\n    if (!command) {\n        console.log('Learn It is a tool for creating and consuming knowledge through a structured git repository.');\n        for (const command in commands) {\n            help({ command });\n        }\n\n        return;\n    }\n\n    if (!(command in commands)) {\n        console.log(`No such command '${command}.'`);\n        return;\n    }\n\n    if (commands[command].description) {\n        documentation(command, null, commands[command]);\n        return;\n    }\n\n    if (!subCommand) {\n        for (const subCommand in commands[command]) {\n            help({ command, subCommand });\n        }\n\n        return;\n    }\n\n    if (!(subCommand in commands[command])) {\n        console.log(`No such command sequence '${command} ${subCommand}'`);\n        return;\n    }\n\n    documentation(command, subCommand, commands[command][subCommand]);\n};\n\nconst helpCommand = {\n    description: 'Prints documentation for CLI commands. You can pass hints to limit the return.',\n    args: {\n        'command': {\n            description: 'Only print documentation of the specified command.',\n            type: 'STR',\n            named: false,\n            optional: true,\n        },\n        'subCommand': {\n            description: 'Only print documentation of the specified sub-command',\n            type: 'STR',\n            named: false,\n            optional: true,\n        },\n    },\n    command: help,\n};\n\nconst writerCommands = {\n    'init': courses.create,\n    'new': {\n        'module': modules.create,\n        'chapter': chapters.create,\n        'step': steps.create,\n        'command': createCommand,\n    },\n    'list': {\n        'modules': modules.list,\n        'chapters': chapters.list,\n    },\n    'update': {\n        'step': steps.update,\n    },\n    'revert': {\n        'step': steps.revert,\n    },\n    'delete': {\n        'module': modules.delete,\n        'chapter': chapters.delete,\n        'command': deleteCommand,\n    },\n    'finish': {\n        'chapter': chapters.finish,\n    },\n    'summarize': {\n        'course': courses.summarize,\n        'module': modules.summarize,\n        'chapter': chapters.summarize,\n    },\n    'lock': courses.lock,\n    'unlock': courses.unlock,\n    ...general,\n};\n\nconst readerCommands = {\n    'start': instructor,\n    'output': output,\n};\n\nconst commands = {};\n\nasync function learnit() {\n    const [command, ...rest] = process.argv.slice(2);\n\n    if (await isGitRepo()) {\n        const { locked } = await getBranchConfig('main');\n        \n        if (!locked) {\n            Object.assign(commands, writerCommands);\n        }\n\n        Object.assign(commands, readerCommands);\n    } else {\n        Object.assign(commands, writerCommands);\n    }\n\n    Object.assign(commands, { help: helpCommand, download: general.download });\n\n    if (!command || !(command in commands)) {\n        help({});\n        process.exit();\n    }\n\n    if (!rest.length) {\n        if ('command' in commands[command] && commands[command].command instanceof Function) {\n            commands[command].command({});\n        } else {\n            help({ command });\n            process.exit();\n        }\n    } else {\n        if (commands[command].command instanceof Function) {\n            processCommand(commands[command], rest);\n        } else {\n            processCommand(commands[command][rest[0]], rest.slice(1));\n        }\n    }\n}\n\nlearnit();\n"]}