Improved copy & quit options.
This commit is contained in:
parent
4065f3d4d6
commit
e85a0f45f9
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const blessed = require('neo-blessed');
|
const blessed = require('neo-blessed');
|
||||||
|
const clipboard = require('clipboardy');
|
||||||
|
|
||||||
const argv = require('./argv');
|
const argv = require('./argv');
|
||||||
const { renderReleases, renderScene } = require('./tui/render');
|
const { renderReleases, renderScene } = require('./tui/render');
|
||||||
|
@ -46,6 +47,11 @@ async function init() {
|
||||||
const method = getMethod();
|
const method = getMethod();
|
||||||
const result = await method.fetch();
|
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) {
|
if (argv.render) {
|
||||||
method.render(result, screen);
|
method.render(result, screen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,11 @@ const { argv } = yargs
|
||||||
.option('debug', {
|
.option('debug', {
|
||||||
describe: 'Show error stack traces',
|
describe: 'Show error stack traces',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
})
|
||||||
|
.option('quit', {
|
||||||
|
describe: 'Exit after fetching data. Usually used with --copy.',
|
||||||
|
type: 'boolean',
|
||||||
|
alias: 'q',
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = argv;
|
module.exports = argv;
|
||||||
|
|
|
@ -9,8 +9,6 @@ const scrapers = require('./scrapers');
|
||||||
function findSite(url) {
|
function findSite(url) {
|
||||||
const { origin } = new URL(url);
|
const { origin } = new URL(url);
|
||||||
|
|
||||||
console.log(origin);
|
|
||||||
|
|
||||||
return Object.entries(networks)
|
return Object.entries(networks)
|
||||||
.reduce((foundNetwork, [networkId, network]) => foundNetwork || Object.entries(network.sites)
|
.reduce((foundNetwork, [networkId, network]) => foundNetwork || Object.entries(network.sites)
|
||||||
.reduce((foundSite, [siteId, site]) => {
|
.reduce((foundSite, [siteId, site]) => {
|
||||||
|
@ -73,10 +71,12 @@ async function fetchScene(url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const scene = await scraper.fetchScene(url, site);
|
const scene = await scraper.fetchScene(url, site);
|
||||||
|
const filename = deriveFilename(scene);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...scene,
|
...scene,
|
||||||
filename: deriveFilename(scene),
|
filename,
|
||||||
|
copy: filename,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,6 @@ const config = require('config');
|
||||||
const blessed = require('neo-blessed');
|
const blessed = require('neo-blessed');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const opn = require('opn');
|
const opn = require('opn');
|
||||||
const clipboard = require('clipboardy');
|
|
||||||
|
|
||||||
const argv = require('../argv');
|
|
||||||
const formatters = require('./formatters');
|
const formatters = require('./formatters');
|
||||||
|
|
||||||
function renderReleases(scenes, screen) {
|
function renderReleases(scenes, screen) {
|
||||||
|
@ -106,10 +103,6 @@ function renderReleases(scenes, screen) {
|
||||||
|
|
||||||
function renderScene(scene, _screen) {
|
function renderScene(scene, _screen) {
|
||||||
console.log(scene);
|
console.log(scene);
|
||||||
|
|
||||||
if (argv.copy) {
|
|
||||||
clipboard.writeSync(scene.filename);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in New Issue