2022-03-16 19:07:36 -04:00
|
|
|
import {ArgError, ArgParser} from '/scripts/lib/arg-parser';
|
2022-03-17 12:19:54 -04:00
|
|
|
import {copyWithDependencies, progressBar} from '/scripts/lib/utils';
|
2022-03-16 19:07:36 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BitBurner autocomplete
|
|
|
|
* @param data {server: string[], txts: string[], scripts: string[], flags: string[]} - Contextual information
|
|
|
|
* @returns {string[]} - Pool of autocomplete options
|
|
|
|
*/
|
|
|
|
export function autocomplete(data) {
|
|
|
|
return [...data.servers, ...data.scripts];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @param {NS} ns **/
|
|
|
|
export async function main(ns) {
|
|
|
|
// Setup
|
|
|
|
ns.disableLog('ALL');
|
|
|
|
const argParser = new ArgParser('copy.js', 'Copy a file/script to a device along with any dependencies.', null, [
|
|
|
|
{name: 'file', desc: 'File to copy', type: 'string'},
|
|
|
|
{name: 'device', desc: 'Device to copy file(s) to', type: 'string'},
|
|
|
|
{name: 'noDeps', desc: 'Skip copying dependencies', flags: ['-d', '--no-deps'], type: 'bool'},
|
2022-03-17 12:19:54 -04:00
|
|
|
{name: 'silent', desc: 'Suppress program output', flags: ['-s', '--silent'], type: 'bool'}
|
2022-03-16 19:07:36 -04:00
|
|
|
], true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Run
|
|
|
|
const args = argParser.parse(ns.args);
|
|
|
|
|
|
|
|
// Banner
|
|
|
|
if(!args['silent']) {
|
|
|
|
ns.tprint('===================================================');
|
|
|
|
ns.tprint(`Copying: ${args['device']}`);
|
|
|
|
ns.tprint('===================================================');
|
|
|
|
ns.tprint('');
|
|
|
|
ns.tprint('Copying Files:');
|
|
|
|
await ns.sleep(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy files & create download bar
|
|
|
|
if(args['noDeps']) {
|
|
|
|
await ns.scp(args['file'], args['device']);
|
2022-03-17 12:19:54 -04:00
|
|
|
if(!args['silent']) await progressBar(ns, args['file']);
|
2022-03-16 19:07:36 -04:00
|
|
|
} else {
|
|
|
|
const files = await copyWithDependencies(ns, args['file'], args['device']);
|
|
|
|
if(!args['silent']) {
|
|
|
|
for(let file of files) {
|
2022-03-17 12:19:54 -04:00
|
|
|
await progressBar(ns, file);
|
2022-03-16 19:07:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done message
|
|
|
|
if(!args['silent']) {
|
|
|
|
ns.tprint('');
|
|
|
|
ns.tprint('Done!');
|
|
|
|
ns.tprint('');
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
if(err instanceof ArgError) return ns.tprint(argParser.help(err.message));
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|