Skip to content

Commit

Permalink
Merge pull request #35 from bchainhub/update/feature-download-06
Browse files Browse the repository at this point in the history
New line fixes
  • Loading branch information
rastislavcore authored Aug 28, 2024
2 parents feb9a6a + 0977402 commit b1bdd01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions bin/txms
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const args = parseArgs(process.argv.slice(2));

if (process.stdin.isTTY) {
// If the script is run with a TTY, process the command-line arguments
run(args.kind, args.value, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename);
run(args.kind, args.value, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename, '\n');
} else {
// If data is being piped into the script, capture it
let content = '';
Expand All @@ -126,16 +126,16 @@ if (process.stdin.isTTY) {
content = content.trim();

if (!content) {
run(args.kind, args.value, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename);
run(args.kind, args.value, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename, '');
} else {
run(args.kind, content, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename);
run(args.kind, content, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename, '');
}
});
}

async function run(kind, value, output, countryCodes, phoneNumbers, download, filename) {
async function run(kind, value, output, countryCodes, phoneNumbers, download, filename, newline) {
if (!value && kind !== 'version') {
process.stderr.write('Value is required\n');
process.stderr.write('Value is required' + newline);
process.exit(1);
}

Expand All @@ -148,44 +148,44 @@ async function run(kind, value, output, countryCodes, phoneNumbers, download, fi
const packageJsonPath = path.join(__dirname, '../package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
const version = packageJson.version;
process.stdout.write(version);
process.stdout.write(version + newline);
process.exit(0);
} else if (kind === 'encode' || kind === 'e') {
if (download) {
const filenm = await txms.downloadMessage(value, filename ? filename : undefined, output);
process.stdout.write(`TxMS file was downloaded as "${filenm}".\n`);
process.stdout.write(`TxMS file was downloaded as "${filenm}".${newline}`);
} else {
const encoded = txms.encode(value);
process.stdout.write(encoded);
process.stdout.write(encoded + newline);
}
process.exit(0);
} else if (kind === 'decode' || kind === 'd') {
const decoded = txms.decode(value);
process.stdout.write(decoded);
process.stdout.write(decoded + newline);
process.exit(0);
} else if (kind === 'getendpoint' || kind === 'g') {
const endpoint = txms.getEndpoint(value, countryCodes);
let endpointString = Object.keys(endpoint).map(key => {
const numbers = endpoint[key].join(',');
return `${key}:${numbers}`;
}).join(';');
process.stdout.write(endpointString);
process.stdout.write(endpointString + newline);
process.exit(0);
} else if (kind === 'sms') {
const message = txms.encode(value);
const sms = txms.sms(phoneNumbers ? phoneNumbers.split(',') : true, message);
process.stdout.write(sms);
process.stdout.write(sms + newline);
process.exit(0);
} else if (kind === 'mms') {
const message = txms.encode(value);
const mms = txms.mms(phoneNumbers ? phoneNumbers.split(',') : true, message);
process.stdout.write(mms);
process.stdout.write(mms + newline);
process.exit(0);
} else {
throw new Error('Invalid type specified.');
throw new Error('Invalid type specified.' + newline);
}
} catch (err) {
process.stderr.write(`${err.message}\n`);
process.stderr.write(`${err.message}${newline}`);
process.exit(1);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "txms.js",
"version": "1.2.8",
"version": "1.2.9",
"description": "Transaction messaging service protocol",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit b1bdd01

Please sign in to comment.