Improved copy & quit options.

This commit is contained in:
ThePendulum 2019-03-24 03:08:51 +01:00
parent 4065f3d4d6
commit e85a0f45f9
4 changed files with 14 additions and 10 deletions

View File

@ -1,6 +1,7 @@
'use strict';
const blessed = require('neo-blessed');
const clipboard = require('clipboardy');
const argv = require('./argv');
const { renderReleases, renderScene } = require('./tui/render');
@ -46,6 +47,11 @@ async function init() {
const method = getMethod();
const result = await method.fetch();
if (argv.copy && result.copy) {
clipboard.writeSync(result.copy);
console.log(`Result copied to clipboard: ${result.copy}`);
}
if (argv.render) {
method.render(result, screen);
}

View File

@ -21,6 +21,11 @@ const { argv } = yargs
.option('debug', {
describe: 'Show error stack traces',
type: 'boolean',
})
.option('quit', {
describe: 'Exit after fetching data. Usually used with --copy.',
type: 'boolean',
alias: 'q',
});
module.exports = argv;

View File

@ -9,8 +9,6 @@ const scrapers = require('./scrapers');
function findSite(url) {
const { origin } = new URL(url);
console.log(origin);
return Object.entries(networks)
.reduce((foundNetwork, [networkId, network]) => foundNetwork || Object.entries(network.sites)
.reduce((foundSite, [siteId, site]) => {
@ -73,10 +71,12 @@ async function fetchScene(url) {
}
const scene = await scraper.fetchScene(url, site);
const filename = deriveFilename(scene);
return {
...scene,
filename: deriveFilename(scene),
filename,
copy: filename,
};
}

View File

@ -4,9 +4,6 @@ const config = require('config');
const blessed = require('neo-blessed');
const moment = require('moment');
const opn = require('opn');
const clipboard = require('clipboardy');
const argv = require('../argv');
const formatters = require('./formatters');
function renderReleases(scenes, screen) {
@ -106,10 +103,6 @@ function renderReleases(scenes, screen) {
function renderScene(scene, _screen) {
console.log(scene);
if (argv.copy) {
clipboard.writeSync(scene.filename);
}
}
module.exports = {