UNPKG

atcoder-cli

Version:
2 lines 36.4 kB
#!/usr/bin/env node !function(t){var e={};function o(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,o),s.l=!0,s.exports}o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)o.d(n,s,function(e){return t[e]}.bind(null,s));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=15)}([function(t,e,o){"use strict";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var o in t)Object.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});const i=n(o(3)),a=o(1);e.defaults={"oj-path":"","default-contest-dirname-format":"{ContestID}","default-task-dirname-format":"{tasklabel}","default-test-dirname-format":"tests","default-task-choice":"inquire","default-template":""};const r=(()=>{let t=null;return async()=>{if(null!==t)return t;const n=(await Promise.resolve().then(()=>s(o(8)))).default;return t=new n({defaults:e.defaults,projectName:a.name})}})();e.default=r,e.getConfigDirectory=async function(){return i.default.resolve((await r()).path,"..")}},function(t){t.exports=JSON.parse('{"name":"atcoder-cli","version":"2.2.0","description":"AtCoder command line tools","keywords":["atcoder","competitive-programming","cli"],"author":"Tatamo","license":"BSD-3-Clause","repository":{"type":"git","url":"https://github.com/Tatamo/atcoder-cli.git"},"bin":{"acc":"bin/index.js"},"files":["bin/","schema/","package.json","LICENSE","README.md"],"scripts":{"test":"jest","test-w":"jest --watchAll","build":"npm run clean && tsc && webpack --mode production","clean":"rimraf bin src/**/*.{js,d.ts}","watch:tsc":"tsc --watch","watch:webpack":"webpack --mode development --watch","watch":"tsc && npm-run-all -p watch:*","prepare":"npm run build"},"dependencies":{"ajv":"^6.10.2","axios":"^0.21.1","commander":"^3.0.1","conf":"^5.0.0","fs-extra":"^8.1.0","inquirer":"^7.0.0","jsdom":"^15.1.1","mkdirp":"^0.5.1","query-string":"^6.8.3","typesafe-di":"^0.1.0","update-notifier":"^4.1.0"},"devDependencies":{"@types/fs-extra":"^8.0.0","@types/inquirer":"6.5.0","@types/jest":"^24.0.18","@types/jsdom":"^12.2.4","@types/mkdirp":"^0.5.2","@types/mock-fs":"^3.6.30","@types/node":"^12.7.5","@types/update-notifier":"^4.1.0","jest":"^24.9.0","mock-fs":"^5.1.1","npm-run-all":"^4.1.5","rimraf":"^3.0.0","ts-jest":"^24.0.2","typescript":"^3.6.3","webpack":"^4.39.3","webpack-cli":"^3.3.8","webpack-node-externals":"^1.7.2"},"jest":{"preset":"ts-jest","testEnvironment":"node"}}')},function(t,e){t.exports=require("jsdom")},function(t,e){t.exports=require("path")},function(t,e){t.exports=require("util")},function(t,e,o){"use strict";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var o in t)Object.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});const i=n(o(18));class a{constructor(t){this.session=t,this._login=null}static get base_url(){return"https://atcoder.jp/"}static get login_url(){return`${a.base_url}login`}static getContestURL(t){return`${a.base_url}contests/${t}`}static getTaskURL(t,e){return`${a.getContestURL(t)}/tasks${void 0===e?"":`/${e}`}`}async checkSession(t=!1){return null===this._login||t?this._login=await this.check():this._login}async check(){const t=`${a.getContestURL("abc001")}/submit`;return 302!==(await this.session.get(t,{maxRedirects:0,validateStatus:t=>t>=200&&t<300||302===t})).status}async login(){return await this.checkSession()?(console.error("you logged-in already"),!0):this.session.transaction(async()=>{const{csrf_token:t}=await this.getCSRFToken(),e=await Promise.resolve().then(()=>s(o(6))),{username:n,password:r}=await e.prompt([{type:"input",message:"username:",name:"username"},{type:"password",message:"password:",name:"password"}]),c=await this.session.post(a.login_url,i.default.stringify({username:n,password:r,csrf_token:t}),{maxRedirects:0,validateStatus:t=>t>=200&&t<300||302===t}),l="/login"!==c.headers.location;return l&&await c.saveSession(),l})}async getCSRFToken(){const{JSDOM:t}=await Promise.resolve().then(()=>s(o(2))),e=await this.session.get(a.login_url,{headers:{Cookie:""}}),{document:n}=new t(e.data).window,i=n.getElementsByName("csrf_token")[0];return await e.saveSession(),{csrf_token:i.value}}async logout(){await this.session.removeSession(),this._login=null}async contest(t){const e=a.getContestURL(t),n=await this.session.get(e),{JSDOM:i}=await Promise.resolve().then(()=>s(o(2))),{document:r}=new i(n.data).window,c=/^(.*) - AtCoder$/;return{id:t,title:c.test(r.title)?c.exec(r.title)[1]:r.title,url:e}}async tasks(t){const e=await this.session.get(a.getTaskURL(t)),{JSDOM:n}=await Promise.resolve().then(()=>s(o(2))),{document:i}=new n(e.data).window,r=i.querySelector("#main-div .row table>tbody");if(null===r)return[];const c=[];for(const t of r.querySelectorAll("tr")){const e=t.children[0].children[0].getAttribute("href").split("/").pop(),o=t.children[0].children[0].text,n=t.children[1].children[0].text,s=`${a.base_url}${t.children[0].children[0].getAttribute("href").substring(1)}`;c.push({id:e,label:o,title:n,url:s})}return c}async task(t,e){const o=await this.tasks(t);for(const t of o)if(t.id===e)return t;throw new Error(`Task ${e} not found.`)}}e.AtCoder=a},function(t,e){t.exports=require("inquirer")},function(t,e,o){"use strict";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const s=n(o(0)),i=n(o(9)),a=o(4).promisify(i.default.exec);class r{static async getPath(){let t=(await s.default()).get("oj-path");if(void 0===t||""===t.trim()){const e="win32"===process.platform?"where oj":"which oj";t=await a(e).then(t=>t.stdout.trim()).catch(()=>"")}return""===t?null:t}static async checkAvailable(){const t=await r.getPath();if(null===t)return!1;const e=""!==(await a(`${t} -h`).then(t=>t.stdout).catch(()=>"")).trim(),o=await s.default();return e&&o.get("oj-path")!==t&&o.set("oj-path",t),e}static async call(t){const e=await r.getPath();if(null===e)throw new Error("online-judge-tools not installed.");await new Promise(o=>{i.default.spawn(e,t,{stdio:"inherit"}).on("close",()=>o())})}}e.OnlineJudge=r},function(t,e){t.exports=require("conf")},function(t,e){t.exports=require("child_process")},function(t,e,o){"use strict";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var o in t)Object.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});const i=o(11),a=o(3),r=n(o(19)),c=o(4),l=o(7),d=n(o(0)),u=o(12),f=o(14);async function p(t){const o=c.promisify(i.readFile);let n=void 0!==t?t:process.cwd();const s=await(async()=>{let t=null;for(;;)try{let s=a.resolve(n,e.PROJECT_JSON_FILE_NAME);return t=JSON.parse(await o(s,"utf8")),t}catch(t){if("ENOENT"!==t.code)throw t;{const t=a.resolve(n,"..");if(t===n)throw new Error(`${e.PROJECT_JSON_FILE_NAME} not found.`);n=t}}})(),[r,l]=await h(s);if(r)return{path:n,data:s};throw new Error(`failed to validate JSON: ${l}`)}async function m(t,o){if(void 0===o&&(o=(await p()).path),void 0===o)throw new Error("Cannot find project directory path");const[n,s]=await h(t);if(!n)throw console.error("JSON validation failed:"),new Error(s);{const n=JSON.stringify(t,void 0,2);await c.promisify(i.writeFile)(a.resolve(o,e.PROJECT_JSON_FILE_NAME),n)}}async function h(t){const e=new((await Promise.resolve().then(()=>s(o(13)))).default),n=await Promise.resolve().then(()=>s(o(27))),i=e.compile(n);return i(t)?[!0,null]:[!1,e.errorsText(i.errors)]}function g(t,e){return t.replace(/{([a-zA-Z0-9]+)}/g,(t,o)=>(t=>{switch(t){case"ContestID":return e.id;case"CONTESTID":return e.id.toUpperCase();case"TailNumberOfContestID":const t=/\d+$/.exec(e.id);return null===t?"":t[0];case"ContestTitle":return e.title}throw new Error(`pattern "{${t}} is not defined. use --help option to get more information."`)})(o))}function w(t,e,o,n){return t.replace(/{([a-zA-Z0-9]+)}/g,(t,s)=>(t=>{switch(t){case"TaskLabel":return e.label;case"tasklabel":return e.label.toLowerCase();case"TASKLABEL":return e.label.toUpperCase();case"TaskID":return e.id;case"TASKID":return e.id.toUpperCase();case"TaskTitle":return e.title;case"ContestID":return n.id;case"CONTESTID":return n.id.toUpperCase();case"TailNumberOfContestID":const t=/\d+$/.exec(n.id);return null===t?"":t[0];case"ContestTitle":return n.title;case"index0":return o.toString();case"index1":return(o+1).toString();case"alphabet":return y(o);case"ALPHABET":return y(o).toUpperCase()}throw new Error(`pattern "{${t}} is not defined. use --help option to get more information."`)})(s))}function y(t){if(t<0)throw new Error("invalid number");let e="";do{e=(t%26+10).toString(36)+e}while((t=Math.floor(t/26)-1)>=0);return e}e.PROJECT_JSON_FILE_NAME="contest.acc.json",e.findProjectJSON=p,e.detectTaskByPath=async function(t){void 0===t&&(t=process.cwd());try{const{path:e,data:{contest:o,tasks:n}}=await p();if(t===e)return{contest:o,task:null};const s=t.split(a.sep)[e.split(a.sep).length];let i=null;for(const t of n)if(void 0!==t.directory&&a.resolve(e,t.directory.path)===a.resolve(e,s)){i=t;break}return{contest:o,task:i}}catch(t){return{contest:null,task:null}}},e.saveProjectJSON=m,e.validateProjectJSON=h,e.init=async function(t,o,n){const s=await f.getAtCoder();await s.checkSession()||await s.login();const[a,r]=await Promise.all([s.contest(t),s.tasks(t)]).catch(()=>{throw new Error("failed to get contest information.")}),l=g(void 0!==n.contestDirnameFormat?n.contestDirnameFormat:(await d.default()).get("default-contest-dirname-format"),a);try{await c.promisify(i.mkdir)(l)}catch(t){if(!0!==n.force)throw new Error(`${l} file/directory already exists.`)}process.chdir(l);const p=process.cwd(),h={contest:a,tasks:r};return await m(h,process.cwd()),console.log(`${l}/${e.PROJECT_JSON_FILE_NAME} created.`),void 0!==o&&await u.installContestTemplate(a,o,p,!0),h},e.installTask=async function(t,e,o,n){const{task:s,index:i,contest:a,template:f}=t,p=void 0!==f?f.task:void 0,m=process.cwd();await c.promisify(r.default)(o),process.chdir(o),await c.promisify(r.default)(e),process.chdir(e);const h=void 0!==n&&!0===n.tests;let g=null;h&&(g=w(void 0!==p&&void 0!==p.testdir?p.testdir:(await d.default()).get("default-test-dirname-format"),s,i,a),l.OnlineJudge.checkAvailable()?await l.OnlineJudge.call(["dl",s.url,"-d",g]):console.error("online-judge-tools is not available. downloading of sample cases skipped.")),void 0!==p&&await u.installTaskTemplate(t,{contest:o,task:process.cwd()},!0),process.chdir(m);const y={directory:{path:e}};return h&&(y.directory.testdir=g),void 0!==p&&void 0!==p.submit&&(y.directory.submit=w(p.submit,s,i,a)),Object.assign(s,y)},e.formatContestDirname=g,e.formatTaskDirname=w},function(t,e){t.exports=require("fs")},function(t,e,o){"use strict";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var o in t)Object.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});const i=o(4),a=o(11),r=o(3),c=o(0),l=n(o(9)),d=o(10),u=o(20);async function f(t){const o=await c.getConfigDirectory(),n=JSON.parse(await i.promisify(a.readFile)(r.resolve(o,t,e.TEMPLATE_JSON_FILE_NAME),"utf8")),[s,l]=await p(n);if(!s)throw new Error(l);return{name:t,...n}}async function p(t){const e=new((await Promise.resolve().then(()=>s(o(13)))).default),n=e.compile(await Promise.resolve().then(()=>s(o(22))));return n(t)?[!0,null]:[!1,e.errorsText(n.errors)]}e.TEMPLATE_JSON_FILE_NAME="template.json",e.getTemplate=f,e.getTemplates=async function(){const t=await c.getConfigDirectory(),o=await i.promisify(a.readdir)(t),n=[];for(const t of o)try{const e=await f(t);n.push(e)}catch(o){"ENOTDIR"!==o.code&&"ENOENT"!==o.code&&console.error(`Error occurred in ${r.resolve(t,e.TEMPLATE_JSON_FILE_NAME)}:\n ${o.toString()}`)}return n},e.validateTemplateJSON=p,e.installContestTemplate=async function(t,e,o,n=!1){const s=void 0!==e.contest?e.contest:{},a=process.cwd();process.chdir(o);const f=r.resolve(await c.getConfigDirectory(),e.name),p=await u.importFsExtra();if(void 0!==s.static)for(const e of s.static){const o=r.resolve(f,"string"==typeof e?e:e[0]),s=r.resolve(process.cwd(),"string"==typeof e?e:d.formatContestDirname(e[1],t));try{await p.copy(o,s)}catch(t){console.error(t.toString())}n&&console.log(`"${o}" -> "${s}"`)}if(void 0!==s.cmd){n&&console.log(`Command:\n exec \`${s.cmd}\``);const e={...process.env,TEMPLATE_DIR:f,CONTEST_DIR:o,CONTEST_ID:t.id},{stdout:a,stderr:r}=await i.promisify(l.default.exec)(s.cmd,{env:e});n&&""!==a&&console.log(a),""!==r&&console.error(r)}process.chdir(a)},e.installTaskTemplate=async function(t,e,o=!1){const{task:n,index:s,contest:a,template:f}=t;if(void 0===f)throw new Error("no template is given");const p=f.task,m=process.cwd();process.chdir(e.task);const h=r.resolve(await c.getConfigDirectory(),f.name),g=await u.importFsExtra();for(const t of p.program){const e=r.resolve(h,"string"==typeof t?t:t[0]),i=r.resolve(process.cwd(),"string"==typeof t?t:d.formatTaskDirname(t[1],n,s,a));try{await g.copy(e,i,{overwrite:!1,errorOnExist:!0}),o&&console.log(`"${e}" -> "${i}"`)}catch(t){console.error(`Skip: "${e}" -> "${i}"`)}}if(void 0!==p.static)for(const t of p.static){const e=r.resolve(h,"string"==typeof t?t:t[0]),i=r.resolve(process.cwd(),"string"==typeof t?t:d.formatTaskDirname(t[1],n,s,a));try{await g.copy(e,i)}catch(t){console.error(t.toString())}o&&console.log(`"${e}" -> "${i}"`)}if(void 0!==p.cmd){o&&console.log(`Command:\n exec \`${p.cmd}\``);const t={...process.env,TEMPLATE_DIR:h,TASK_DIR:e.task,TASK_ID:n.id,TASK_INDEX:s.toString(),CONTEST_DIR:e.contest,CONTEST_ID:a.id},{stdout:r,stderr:c}=await i.promisify(l.default.exec)(p.cmd,{env:t});o&&""!==r&&console.log(r),""!==c&&console.error(c)}process.chdir(m)}},function(t,e){t.exports=require("ajv")},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});const n=o(23),s=o(24),i=o(5),a=o(26);e.CookieDesign=n.Design.bind("CookieConstructor",()=>a.Cookie),e.SessionDesign=n.Design.bind("session",async t=>new s.Session(await t.CookieConstructor)),e.AtCoderDesign=n.Design.bind("atcoder",async t=>new i.AtCoder(await t.session)),e.productionAtCoderDesign=e.AtCoderDesign.merge(e.CookieDesign).merge(e.SessionDesign),e.getAtCoder=async()=>{const{container:{atcoder:t}}=await e.productionAtCoderDesign.resolve({});return t}},function(t,e,o){"use strict";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var o in t)Object.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});const i=n(o(16)),a=o(1),r=s(o(17)),c=s(o(28));n(o(29)).default({pkg:{name:a.name,version:a.version}}).notify({isGlobal:!0}),i.default.version(a.version,"-v, --version"),i.default.command("new <contest-id>").alias("n").action(r.setup).option("-c, --choice <choice>","how to choice tasks to add",/^(inquire|all|none|rest|next)$/i).option("-f, --force","ignore existent directories").option("-d, --contest-dirname-format <format>",'specify the format to name contest directory. defaults to "{ContestID}"').option("-t, --task-dirname-format <format>",'specify the format to name task directories. defaults to "{tasklabel}"').option("--no-tests","skip downloading sample cases by using online-judge-tools").option("--template <name>","specify the provisioning template").option("--no-template","do not use templates, even if specified by global config").description("create new contest project directory").on("--help",()=>{console.log(""),console.log(c.task_choices)}),i.default.command("add").alias("a").action(r.add).option("-c, --choice <choice>","how to choice tasks to add",/^(inquire|all|none|rest|next)$/i).option("-f, --force","ignore existent directories").option("-t, --task-dirname-format <format>",'specify the format to name task directories. defaults to "{tasklabel}"').option("--no-tests","skip downloading sample cases by using online-judge-tools").option("--template <name>","specify the provisioning template").option("--no-template","do not use templates, even if specified by global config").description("add new directory for the task in the project directory").on("--help",()=>{console.log(""),console.log(c.task_choices)}),i.default.command("submit [filename] [facade-options...]").alias("s").option("-c, --contest <contest-id>","specify contest id to submit").option("-t, --task <task-id>","specify task id to submit").option("-s, --skip-filename","specify that filename is not given (the first argument will be parsed as not a filename, but a facade option)").action(r.submit).description("submit the program").on("--help",()=>{console.log(""),console.log(c.submit_facade_options)}),i.default.command("login").action(r.login).description("login to AtCoder"),i.default.command("logout").action(r.logout).description("delete login session information"),i.default.command("session").action(r.session).description("check login or not"),i.default.command("contest [contest-id]").action(r.contest).option("-t, --title","show contest title").option("-i, --id","show contest id").option("-u, --url","show contest url").description("get contest information"),i.default.command("task [contest-id] [task-id]").action(r.task).option("-l, --label","show task label").option("-t, --title","show task title").option("-i, --id","show task id").option("-u, --url","show task url").description("get task"),i.default.command("tasks [contest-id]").action(r.tasks).option("-i, --id","show task id").description("get tasks"),i.default.command("url [contest] [task]").option("-c, --check","check the specified contest and/or task id is valid").action(r.url).description("get contest or task URL"),i.default.command("format <format> <contest-id> [task-id]").action(r.format).description("format string with contest and/or task information.").on("--help",()=>{console.log(""),console.log(c.format_strings)}),i.default.command("check-oj").action(r.checkOJAvailable).description("check whether online-judge-tools related functions are available or not").on("--help",()=>{console.log(""),console.log(c.online_judge_tools)}),i.default.command("config [key] [value]").option("-d","delete the option value and set back to the default").action(r.config).description("get or set values of global options").on("--help",()=>{console.log(""),console.log(c.global_config)}),i.default.command("config-dir").action(r.configDir).description("get the path of atcoder-cli config directory"),i.default.command("templates").action(r.getTemplateList).description("show user templates in the config directory").on("--help",()=>{console.log(""),console.log(c.provisioning_templates)}),i.default.on("--help",()=>{console.log(""),console.log(c.default_help)}),i.default.on("command:*",(function(){console.error("Invalid command: %s\nUse `acc --help` for a list of available commands.",i.default.args.join(" "))})),i.default.parse(process.argv)},function(t,e){t.exports=require("commander")},function(t,e,o){"use strict";var n=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var o in t)Object.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});const s=o(5),i=o(7),a=o(10),r=n(o(0)),c=o(12),l=o(14);function d(t,...e){return e=e.map(t=>void 0!==t?t:""),String.raw(t,...e)}async function u(t){if(!1!==t&&(void 0!==t&&!0!==t||(t=(await r.default()).get("default-template")),""!==t))return await c.getTemplate(t).catch(e=>{throw new Error(`Failed to load template "${t}".\n ${e}`)})}async function f(t){try{const{path:e,data:o}=await a.findProjectJSON(),{contest:n,tasks:s}=o,i=await(async e=>{let o=!1;if(void 0===e&&(e=(await r.default()).get("default-task-choice"),o=!0),!function(t){switch(t){case"inquire":case"all":case"none":case"rest":case"next":return!0}return!1}(e))throw new Error(`Invalid option is given with --choice. (inquire/all/none/rest/next)${o?'\nIf you did not set the --choice option, check the "default-task-choice" option in global config by using `acc config`.':""}`);return await p(s,e,t.force)})(t.choice),c=await u(t.template);let l=0;for(const{index:o,task:d}of i){if(!0!==t.force&&void 0!==d.directory)continue;const i=void 0!==t.taskDirnameFormat?t.taskDirnameFormat:(await r.default()).get("default-task-dirname-format"),u=a.formatTaskDirname(i,d,o,n);s[o]=await a.installTask({task:d,index:o,contest:n,template:c},u,e,{tests:t.tests}),l++}0===l&&console.error(w("Skip: no task directories were created. use --force option to overwrite existent directories.",33)),await a.saveProjectJSON(Object.assign(o,{tasks:s}))}catch(t){console.error(w(t.message,33))}}async function p(t,e,o=!1){switch(e){case"inquire":return await m(t,o);case"all":return t.map((t,e)=>({index:e,task:t}));case"none":return[];case"rest":return t.filter(t=>void 0===t.directory).map((t,e)=>({index:e,task:t}));case"next":const n=h(t);return null!==n?[n]:[];default:throw new Error(`mode "${e}" is not defined"`)}}async function m(t,e=!1){const s=await Promise.resolve().then(()=>n(o(6))),i=h(t);if(!e&&null===i)throw new Error("all tasks are already installed. use --force option to overwrite them.");return(await s.prompt([{type:"checkbox",message:"select tasks",name:"tasks",choices:t.map((t,o)=>({name:`${t.label} ${t.title}`,value:{index:o,task:t},disabled:e||void 0===t.directory?()=>!1:()=>"already installed",checked:null!==i&&o===i.index}))}])).tasks}function h(t){for(let e=0;e<t.length;e++)if(void 0===t[e].directory)return{index:e,task:t[e]};return null}function g(t){const e=t.map(t=>t.map(t=>t.length)).reduce((t,e)=>t.map((t,o)=>Math.max(t,e[o])));return t.map(t=>t.reduceRight((t,o,n)=>o.padEnd(e[n])+" "+t)).join("\n")}function w(t,...e){return process.stdout.isTTY?`${e.map(t=>`[${t}m`).join("")}${t}`:t}e.login=async function(){const t=await l.getAtCoder();console.log(await t.login()?"OK":"login failed")},e.logout=async function(){const t=await l.getAtCoder();await t.logout(),console.log("login session aborted.")},e.session=async function(){const t=await l.getAtCoder();console.log("check login status..."),console.log(await t.checkSession()?"OK":"not login")},e.contest=async function(t,e){const o=!0===e.id,n=!0===e.title,s=!0===e.url,i=({id:t,title:e,url:i})=>g([o||n||s?[o?w(t,37):null,n?w(e,32,1):null,s?i:null].filter(t=>null!==t):[w(t,37),w(e,32,1),i]]);if(void 0===t)try{const{data:{contest:t}}=await a.findProjectJSON();console.log(i(t))}catch(t){console.error(t.message)}else try{const e=await l.getAtCoder();await e.checkSession()||await e.login();const o=await e.contest(t);console.log(i(o))}catch(e){console.error(`contest "${t}" not found.`)}},e.task=async function(t,e,o){const n=!0===o.id,s=!0===o.title,i=!0===o.url,r=!0===o.label,c=({id:t,label:e,title:o,url:a})=>g([n||r||s||i?[n?w(t,37):null,r?w(e,32):null,s?w(o,32,1):null,i?a:null].filter(t=>null!==t):[w(t,37),w(e,32),w(o,32,1),a]]);if(void 0===t&&void 0===e)try{const{task:t}=await a.detectTaskByPath();if(null===t)return void console.error("failed to find the task.");console.log(c(t))}catch(t){console.error(t.message)}else if(void 0!==t&&void 0!==e)try{const o=await l.getAtCoder();await o.checkSession()||await o.login();const n=await o.task(t,e);console.log(c(n))}catch(o){console.error(`task "${e}" of contest "${t}" not found.`)}else console.error("error: specify both the contest id and the task id.")},e.tasks=async function(t,e){const o=!0===e.id,n=t=>g(t.map(({id:t,label:e,title:n,url:s})=>[o?w(t,37):null,w(e,32),w(n,32,1),s].filter(t=>null!==t)));if(void 0===t)try{const{data:{tasks:t}}=await a.findProjectJSON();console.log(n(t))}catch(t){console.error(t.message)}else try{const e=await l.getAtCoder();await e.checkSession()||await e.login();const o=await e.tasks(t);console.log(n(o))}catch(e){console.error(`contest "${t}" not found.`)}},e.url=async function(t,e,o){const n=!0===o.check;if(void 0!==t&&void 0!==e)if(n){const o=await l.getAtCoder();try{const n=await o.tasks(t);for(const{url:o}of n)if(o===s.AtCoder.getTaskURL(t,e))return void console.log(o);console.error(`task "${e}" not found.`)}catch(e){console.error(`contest "${t}" not found.`)}}else console.log(s.AtCoder.getTaskURL(t,e));else if(void 0!==t&&void 0===e)if(n){const e=await l.getAtCoder();try{const{url:o}=await e.contest(t);console.log(o)}catch(e){console.error(`contest "${t}" not found.`)}}else console.log(s.AtCoder.getContestURL(t));else console.log(s.AtCoder.base_url)},e.format=async function(t,e,o){const n=await l.getAtCoder();if(await n.checkSession()||await n.login(),void 0===o)try{const o=await n.contest(e);console.log(a.formatContestDirname(t,o))}catch(t){console.error(t.toString())}else try{const[s,i]=await Promise.all([n.contest(e),n.tasks(e)]);let r=-1;for(let t=0;t<i.length;t++)if(i[t].id===o){r=t;break}if(r<0)return void console.error(`task ${o} not found.`);try{console.log(a.formatTaskDirname(t,i[r],r,s))}catch(t){console.error(t.toString())}}catch(t){console.error("failed to get contest information.")}},e.submit=async function(t,e,o){let n=o.contest,r=o.task;if(!0===o.skipFilename&&void 0!==t&&(e.unshift(t),t=void 0),void 0===t||void 0===n||void 0===r){const{contest:e,task:o}=await a.detectTaskByPath();if(void 0===t&&null!==o&&void 0!==o.directory&&(t=o.directory.submit),void 0===n&&null!==e&&(n=e.id),void 0===r&&null!==o&&(r=o.id),void 0===t)return void console.error("the program file to submit is not found.");if(void 0===n||void 0===r)return console.error(`cannot find the ${void 0===r?"task":"contest"} to submit.`),void console.error(`add ${void 0===r?"-t":"-c"} flag to specify it.`)}if(!await i.OnlineJudge.checkAvailable())return void console.error("online-judge-tools is not available.");const c=await l.getAtCoder(),d=(await c.task(n,r).catch(()=>({url:null}))).url;null!==d?(console.log(`submit to: ${d}`),await i.OnlineJudge.call(["s",d,t,...e])):console.error(`Task ${s.AtCoder.getTaskURL(n,r)} not found.`)},e.checkOJAvailable=async function(){const t=await i.OnlineJudge.checkAvailable(),e=await i.OnlineJudge.getPath();console.log(`online-judge-tools is ${t?"":"not "}available. ${t?"found at:":""}`),t&&console.log(e)},e.configDir=async function(){console.log(await r.getConfigDirectory())},e.config=async function(t,e,o){o.D?await async function(t){const e=await r.default();if(void 0!==t){if(!(t in r.defaults))return void console.error(`invalid option "${t}".`);e.delete(t),console.log(`option "${t}" is set back to default.`)}else console.error("option key is not specified.")}(t):void 0!==t&&void 0!==e?await async function(t,e){const o=await r.default();if(!(t in r.defaults))return void console.error(`invalid option "${t}".`);o.set(t,e),console.log(d`${t} = ${o.get(t)}`)}(t,e):await async function(t){const e=await r.default();if(void 0===t){for(const t of Object.keys(r.defaults))console.log(d`${t}: ${e.get(t)}`);return}if(!(t in r.defaults))return void console.error(`invalid option "${t}".`);console.log(d`${e.get(t)}`)}(t)},e.setup=async function(t,e){try{const o=await u(e.template),{contest:n}=await a.init(t,o,e);console.log(`create project of ${n.title}`),await f(e)}catch(t){console.error(t.message)}},e.add=f,e.selectTasks=p,e.inquireTasks=m,e.getTemplateList=async function(){console.error(w(`search template directories in ${await r.getConfigDirectory()}`,37));const t=await c.getTemplates();console.log(g([[w("NAME",1),"SUBMIT-PROGRAM"]].concat(t.map(t=>[w(t.name,1),t.task.submit]))))}},function(t,e){t.exports=require("query-string")},function(t,e){t.exports=require("mkdirp")},function(t,e,o){"use strict";var n=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var o in t)Object.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0}),e.importFsExtra=async function(){return await Promise.resolve().then(()=>n(o(21)))}},function(t,e){t.exports=require("fs-extra")},function(t){t.exports=JSON.parse('{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","title":"atcoder-cli Task Template File","required":["task"],"properties":{"contest":{"$ref":"#contest"},"task":{"$ref":"#task"}},"definitions":{"contest":{"$id":"#contest","type":"object","properties":{"static":{"$ref":"#copyfile-list"},"cmd":{"type":"string"}}},"task":{"$id":"#task","type":"object","required":["submit","program"],"properties":{"submit":{"type":"string"},"program":{"$ref":"#copyfile-list"},"static":{"$ref":"#copyfile-list"},"cmd":{"type":"string"},"testdir":{"type":"string"}}},"copyfile-list":{"$id":"#copyfile-list","type":"array","items":{"$ref":"#copyfile"}},"copyfile":{"$id":"#copyfile","anyOf":[{"type":"string"},{"type":"array","minItems":2,"maxItems":2,"items":{"type":"string"}}]}}}')},function(t,e){t.exports=require("typesafe-di")},function(t,e,o){"use strict";var n=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var o in t)Object.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});class s{constructor(t){this._currentTransaction=null,this.CookieConstructor=t,this._cookies=null}static async importAxios(){if(null===s._axios){const t=(await Promise.resolve().then(()=>n(o(25)))).default;return s._axios=t.create({headers:{Accept:"text/html"}})}return s._axios}async getCookies(){return null!==this._currentTransaction?this._currentTransaction.cookies:null===this._cookies?this._cookies=await this.CookieConstructor.createLoadedInstance():this._cookies}async get(t,e={}){return this.makeSessionResponse(await(await s.importAxios())(t,{headers:{Cookie:(await this.getCookies()).get().join("; ")},...e}))}async post(t,e,o={}){return this.makeSessionResponse(await(await s.importAxios()).post(t,e,{headers:{Cookie:(await this.getCookies()).get().join("; ")},...o}))}async transaction(t){if(null!==this._currentTransaction)throw new Error("Cannot start a new transaction inside transaction.");const e=await this.getCookies();this._currentTransaction={cookies:e.clone(),isUpdated:!1};try{const e=await t();return this._cookies=this._currentTransaction.cookies,this._currentTransaction.isUpdated&&await this._cookies.saveConfigFile(),e}finally{this._currentTransaction=null}}makeSessionResponse({status:t,data:e,headers:o}){return{status:t,data:e,headers:o,saveSession:async()=>{const t=this.CookieConstructor.convertSetCookies2CookieArray(o["set-cookie"]);await this.saveSessionFromCookies(t)}}}async saveSessionFromCookies(t){(await this.getCookies()).set(t),await this.saveCookie()}async removeSession(){(await this.getCookies()).empty(),await this.saveCookie()}async saveCookie(){null===this._currentTransaction?await(await this.getCookies()).saveConfigFile():this._currentTransaction.isUpdated=!0}}e.Session=s,s._axios=null},function(t,e){t.exports=require("axios")},function(t,e,o){"use strict";var n=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var o in t)Object.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});const s=o(1);class i{constructor(){this.cookies=[]}static async getCookieConfig(){if(null!==i._cookie_conf)return i._cookie_conf;const t=(await Promise.resolve().then(()=>n(o(8)))).default;return i._cookie_conf=new t({defaults:{cookies:[]},configName:"session",projectName:s.name})}static async createLoadedInstance(){const t=new i;return await t.loadConfigFile(),t}get(){return this.cookies}set(t){this.cookies=t}clone(){const t=new i;return t.set(this.cookies.slice()),t}static convertSetCookies2CookieArray(t){return t.map(t=>/^\s*(?:Set-Cookie:\s*)?(.*)$/i.exec(t)[1].trim().split(";")[0])}empty(){this.cookies=[]}async loadConfigFile(){this.cookies=(await i.getCookieConfig()).get("cookies")}async saveConfigFile(){(await i.getCookieConfig()).set("cookies",this.cookies)}}e.Cookie=i,i._cookie_conf=null},function(t){t.exports=JSON.parse('{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","title":"atcoder-cli Contest Project File","required":["contest","tasks"],"properties":{"contest":{"$ref":"#contest"},"tasks":{"$ref":"#tasks"}},"definitions":{"contest":{"$id":"#contest","type":"object","required":["id","title","url"],"properties":{"id":{"type":"string"},"title":{"type":"string"},"url":{"type":"string"}}},"directory":{"$id":"#directory","type":"object","required":["path"],"properties":{"path":{"type":"string"},"submit":{"type":"string"},"testdir":{"type":"string"}}},"task":{"$id":"#task","type":"object","required":["id","label","title","url"],"properties":{"id":{"type":"string"},"label":{"type":"string"},"title":{"type":"string"},"url":{"type":"string"},"directory":{"$ref":"#directory"}}},"tasks":{"$id":"#tasks","type":"array","items":{"$ref":"#task"}}}}')},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.task_choices='Supported arguments for --choice:\n inquire inquire the tasks to add\n all select all tasks\n none select no tasks\n rest select all tasks not added yet\n (without --force option, same with "all")\n next select the top task that is not added yet',e.format_strings="Supported format strings:\n {TaskLabel} task label (e.g. A, B, C, D, ...)\n {tasklabel} task label, lower case \n {TASKLABEL} task label, upper case\n {TaskID} task id (shown as task URL path, e.g. arc100_a)\n {TASKID} task id, upper case\n {TaskTitle} task title\n {index0} 0-based task index\n {index1} 1-based task index\n {alphabet} task index as alphabet: a, b, c, ..., z, aa, ab, ...\n {ALPHABET} task index as alphabet: A, B, C, ..., Z, AA, AB, ...\n {ContestID} contest id (shown as contest URL path, e.g. arc100)\n {CONTESTID} contest id, upper case\n {TailNumberOfContestID} if contest id is arc100, 100 is the tail number. (this format string may be empty, some contests such as abs)\n {ContestTitle} contest title",e.global_config="Global config options list:\n oj-path install path of online-judge-tools (auto detected)\n default-contest-dirname-format default name of contest directory (created by `acc new` command)\n default-task-dirname-format default name of task directory (created by `acc new|add` command)\n default-test-dirname-format default name of sample cases directory\n default-task-choice default --choice option for `acc new|add` command (see also: `acc new|add -h`)\n default-template default template (see also: `acc templates -h`)",e.provisioning_templates="See also:\nhttps://github.com/Tatamo/atcoder-cli#provisioning-templates",e.online_judge_tools="Functions of online-judge-tools linkage:\n downloading sample cases `acc new|add` command\n submit code `acc submit` command",e.submit_facade_options="** experimental (may be changed in future) **\natcoder-cli uses online-judge-tools internally.\npass extra arguments to online-judge-tools:\n `acc submit main.cpp -- -w 10 --no-open`\n \nIf you are using template and want to omit the filename, use -s option:\n `acc submit -s -- -w 10 --no-open`",e.default_help="to get detailed information, use `acc <command> -h`"},function(t,e){t.exports=require("update-notifier")}]);