forked from DebaucheryLibrarian/traxxx
Improved copy & quit options.
This commit is contained in:
parent
4065f3d4d6
commit
e85a0f45f9
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in New Issue