Skip to content

Commit

Permalink
fix: stdout with line-break and strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ephigenia committed Jan 19, 2022
1 parent 78cd664 commit 0fcb79b
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion source/mite-amend.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async function main(timeEntryId, note) {
return getTimeEntryData(timeEntryId)
.then(getUpdatedTimeEntryData.bind(this, program.opts(), note))
.then(entry => updateTimeEntry(entry.id, entry).then(() => entry))
.then(entry => process.stdout.write(`Successfully modified note of time entry (id: ${entry.id})`))
.then(entry => process.stdout.write(`Successfully modified note of time entry (id: ${entry.id})\n`))
.catch(handleError);
}

Expand Down
8 changes: 4 additions & 4 deletions source/mite-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Examples:
throw new GeneralError(err.message);
}
if (value === undefined) {
process.stdout.write(`successfully set "${key}" to the default value`);
process.stdout.write(`successfully set "${key}" to the default value\n`);
} else {
process.stdout.write(`successfully set "${key}" to "${value}"`);
process.stdout.write(`successfully set "${key}" to "${value}"\n`);
}
// make sure file is only write- and readable by the user
const configFilename = config.stores.file.file;
Expand All @@ -66,11 +66,11 @@ Examples:
Get the current value of the "account" config variable:
mite config get account
`)
.action((key) => process.stdout.write(config.get(key)));
.action((key) => process.stdout.write(JSON.stringify(config.get(key)) + '\n'));

program.command('list')
.description('list all currently defined config vars')
.action(() => process.stdout.write(config.get()));
.action(() => process.stdout.write(JSON.stringify(config.get(), null, 2) + '\n'));

program.parse();

Expand Down
2 changes: 1 addition & 1 deletion source/mite-customer-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function main(customerId) {
}
const mite = miteApi(config.get());
return util.promisify(mite.deleteCustomer)(customerId)
.then(() => process.stdout.write(`Successfully deleted customer (id: ${customerId})`))
.then(() => process.stdout.write(`Successfully deleted customer (id: ${customerId})\n`))
.catch(handleError);
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-customer-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function main() {
const format = DataOutput.getFormatFromOptions(opts, config);
const columns = commandOptions.columns.resolve(opts.columns, customersCommand.columns.options);
const tableData = DataOutput.compileTableData(items, columns, format);
process.stdout.write(DataOutput.formatData(tableData, format, columns));
process.stdout.write(DataOutput.formatData(tableData, format, columns) + '\n');
})
.catch(handleError);
} // main
Expand Down
2 changes: 1 addition & 1 deletion source/mite-customer-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function main(name, opts) {
process.stdout.write(`Successfully created customer (id: ${customerId}).
Please use web-interface to modify complicated service & hourly rates settings:
https://${config.get('account')}.mite.yo.lk/customers/${customerId}/edit`);
https://${config.get('account')}.mite.yo.lk/customers/${customerId}/edit\n`);
});
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-customer-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function main(customerId, opts) {
};

return util.promisify(mite.updateCustomer)(customerId, data)
.then(() => process.stdout.write(`Successfully updated customer (id: ${customerId})`))
.then(() => process.stdout.write(`Successfully updated customer (id: ${customerId})\n`))
.catch(handleError);
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function main(timeEntryId) {
const message = (err && err.message) ? err.message : err;
handleError(new Error(`Error while deleted time entry (id: ${timeEntryId}) ${message}`));
}
process.stdout.write(timeEntryId);
process.stdout.write(`${timeEntryId}\n`);
});
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function main(period) {
;
const format = DataOutput.getFormatFromOptions(opts, config);
const report = getReport(items, columns, format, format === FORMAT.TABLE);
process.stdout.write(report);
process.stdout.write(`${report}\n`);
});
} // main

Expand Down
2 changes: 1 addition & 1 deletion source/mite-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function main(timeEntryId) {
...(typeof opts.force === 'boolean' && { force: opts.force })
};
return util.promisify(mite.updateTimeEntry)(timeEntryId, data)
.then(() => process.stdout.write(`Successfully locked time entry (id: ${timeEntryId})`))
.then(() => process.stdout.write(`Successfully locked time entry (id: ${timeEntryId})\n`))
.catch(handleError);
}

Expand Down
12 changes: 6 additions & 6 deletions source/mite-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ function checkResults(options, query, type) {

switch (searchResults.length) {
case 0:
process.stdout.write(`No ${type}s found that match "${query}".`);
process.stdout.write(`No ${type}s found that match "${query}".\n`);
break;
case 1:
return searchResults;
default:
process.stdout.write(`Found multiple ${type}s matching "${query}":`);
searchResults.forEach(current => process.stdout.write(`- ${current.name}`));
process.stdout.write(`Found multiple ${type}s matching "${query}":\n`);
searchResults.forEach(current => process.stdout.write(`- ${current.name}\n`));
break;
}
process.stdout.write(
`Use the exact name of an existing ${type}s. List available ${type}s `+
`using "mite ${type}s"`
`using "mite ${type}s"\n`
);
process.exit(1);
}
Expand Down Expand Up @@ -263,11 +263,11 @@ async function main(note, project, service, minutes, date) {
if (startTracker) {
return miteTracker.start(timeEntryId)
.then(() => {
process.stdout.write(timeEntryId);
process.stdout.write(`${timeEntryId}\n`);
process.exit(0);
});
}
process.stdout.write(timeEntryId);
process.stdout.write(`${timeEntryId}\n`);
process.exit(0);
})
.catch(handleError);
Expand Down
2 changes: 1 addition & 1 deletion source/mite-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function main(timeEntryId) {
})
.then((entry) => {
let url = `https://${config.get('account')}.mite.yo.lk/`;
process.stdout.write('No time entry id given, opening the organisation’s account');
process.stdout.write('No time entry id given, opening the organisation’s account\n');
if (entry) {
url += 'daily/#' + (entry.date_at).replace('-', '/') + '?open=time_entry_' + entry.id;
}
Expand Down
2 changes: 1 addition & 1 deletion source/mite-project-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function main(projectId) {
}
const mite = miteApi(config.get());
return util.promisify(mite.deleteProject)(projectId)
.then(() => process.stdout.write(`Successfully deleted project (id: ${projectId})`))
.then(() => process.stdout.write(`Successfully deleted project (id: ${projectId})\n`))
.catch(handleError);
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-project-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async function main() {
const format = DataOutput.getFormatFromOptions(opts, config);
const columns = commandOptions.columns.resolve(opts.columns, projectsCommand.columns.options);
const tableData = DataOutput.compileTableData(items, columns, format);
process.stdout.write(DataOutput.formatData(tableData, format, columns));
process.stdout.write(DataOutput.formatData(tableData, format, columns) + '\n');
})
.catch(handleError);
} // main
Expand Down
2 changes: 1 addition & 1 deletion source/mite-project-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function main(name, opts) {
process.stdout.write(`Successfully created project (id: ${projectId}).
Please use web-interface to modify complicated service & hourly rates settings:
https://${config.get('account')}.mite.yo.lk/reports/projects/${projectId}`);
https://${config.get('account')}.mite.yo.lk/reports/projects/${projectId}\n`);
});
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-project-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function main(projectId) {
};

return util.promisify(mite.updateProject)(projectId, data)
.then(() => process.stdout.write(`Successfully updated project (id: ${projectId})`))
.then(() => process.stdout.write(`Successfully updated project (id: ${projectId})\n`))
.catch(handleError);
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-service-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function main(serviceId) {
}
const mite = miteApi(config.get());
return util.promisify(mite.deleteService)(serviceId)
.then(() => process.stdout.write(`Successfully deleted service (id: ${serviceId})`))
.then(() => process.stdout.write(`Successfully deleted service (id: ${serviceId})\n`))
.catch(handleError);
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-service-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async function main() {
const format = DataOutput.getFormatFromOptions(opts, config);
const columns = commandOptions.columns.resolve(opts.columns, servicesCommand.columns.options);
const tableData = DataOutput.compileTableData(items, columns, format);
process.stdout.write(DataOutput.formatData(tableData, format, columns));
process.stdout.write(DataOutput.formatData(tableData, format, columns) + '\n');
})
.catch(handleError);
} // main
Expand Down
2 changes: 1 addition & 1 deletion source/mite-service-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function main(serviceId) {
...(typeof opts.updateEntries === 'boolean' && { update_hourly_rate_on_time_entries: true }),
};
return util.promisify(mite.updateProject)(serviceId, data)
.then(() => process.stdout.write(`Successfully updated service (id: ${serviceId})`))
.then(() => process.stdout.write(`Successfully updated service (id: ${serviceId})\n`))
.catch(handleError);
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function main(timeEntryId) {
}
mite.tracker.start(timeEntryId)
// output the id of the entry which was started for piping
.then(() => process.stdout.write(timeEntryId))
.then(() => process.stdout.write(`${timeEntryId}\n`))
.catch(handleError);
}

Expand Down
8 changes: 4 additions & 4 deletions source/mite-stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const { handleError, GeneralError } = require('./lib/errors');
function main() {
const miteTracker = require('./lib/mite-tracker')(config.get());
return miteTracker.get()
.then(id => {
if (!id) {
.then(timeEntryId => {
if (!timeEntryId) {
throw new GeneralError('No running time entry found.');
}
return miteTracker.stop(id);
return miteTracker.stop(timeEntryId);
})
.then((id) => process.stdout.write(id))
.then((timeEntryId) => process.stdout.write(`${timeEntryId}\n`))
.catch(handleError);
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-unlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function main (timeEntryId) {
...(typeof opts.force === 'boolean' && { force: opts.force })
};
return util.promisify(mite.updateTimeEntry)(timeEntryId, data)
.then(() => process.stdout.write(timeEntryId))
.then(() => process.stdout.write(`${timeEntryId}\n`))
.catch(handleError);
}

Expand Down
2 changes: 1 addition & 1 deletion source/mite-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async function main() {
const format = DataOutput.getFormatFromOptions(opts, config);
const columns = commandOptions.columns.resolve(opts.columns, usersCommand.columns.options);
const tableData = DataOutput.compileTableData(items, columns, format);
process.stdout.write(DataOutput.formatData(tableData, format, columns));
process.stdout.write(DataOutput.formatData(tableData, format, columns) + '\n');
})
.catch(handleError);
} // main
Expand Down

0 comments on commit 0fcb79b

Please sign in to comment.