@anaella/cli 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +46 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -114,13 +114,52 @@ ${err.details.map((d) => ` - ${d.field}: ${d.message}`).join("\n")}` : "";
114
114
  `);
115
115
  }
116
116
 
117
+ // src/prompt.ts
118
+ function promptSecret(question) {
119
+ return new Promise((resolve) => {
120
+ const stdin = process.stdin;
121
+ process.stdout.write(question);
122
+ stdin.setRawMode?.(true);
123
+ stdin.resume();
124
+ stdin.setEncoding("utf8");
125
+ let value = "";
126
+ const onData = (chunk) => {
127
+ for (const ch of chunk) {
128
+ const code = ch.charCodeAt(0);
129
+ if (code === 10 || code === 13 || code === 4) {
130
+ stdin.setRawMode?.(false);
131
+ stdin.pause();
132
+ stdin.removeListener("data", onData);
133
+ process.stdout.write("\n");
134
+ resolve(value);
135
+ return;
136
+ }
137
+ if (code === 3) {
138
+ process.stdout.write("\n");
139
+ process.exit(130);
140
+ }
141
+ if (code === 127 || code === 8) {
142
+ if (value.length > 0) {
143
+ value = value.slice(0, -1);
144
+ process.stdout.write("\b \b");
145
+ }
146
+ continue;
147
+ }
148
+ value += ch;
149
+ process.stdout.write("*");
150
+ }
151
+ };
152
+ stdin.on("data", onData);
153
+ });
154
+ }
155
+
117
156
  // src/index.ts
118
157
  var collect = (val, acc) => {
119
158
  acc.push(val);
120
159
  return acc;
121
160
  };
122
161
  var program = new Command();
123
- program.name("anaella").description("CLI for anaella.com \u2014 schedule and publish social posts via the /v1 API.").version("0.1.0").option("--api-key <key>", "ana_ API key (overrides env + config)").option("--api-url <url>", "API base URL").option("--json", "output raw JSON");
162
+ program.name("anaella").description("CLI for anaella.com \u2014 schedule and publish social posts via the /v1 API.").version("0.1.1").option("--api-key <key>", "ana_ API key (overrides env + config)").option("--api-url <url>", "API base URL").option("--json", "output raw JSON");
124
163
  async function withClient(command, fn, columns) {
125
164
  const opts = command.optsWithGlobals();
126
165
  const cfg = resolveConfig({ apiKey: opts.apiKey, apiUrl: opts.apiUrl }, process.env);
@@ -141,9 +180,12 @@ async function withClient(command, fn, columns) {
141
180
  }
142
181
  program.command("login").description("Save an API key (verified against the API) to ~/.config/anaella/config.json").option("--api-key <key>", "the key (else read from stdin)").action(async (opts, command) => {
143
182
  const globals = command.optsWithGlobals();
144
- const key = opts.apiKey || readFileSync2(0, "utf8").trim();
183
+ let key = opts.apiKey;
184
+ if (!key) {
185
+ key = process.stdin.isTTY ? (await promptSecret("Enter your ana_ API key: ")).trim() : readFileSync2(0, "utf8").trim();
186
+ }
145
187
  if (!key) {
146
- process.stderr.write("No key provided (pass --api-key or pipe it on stdin).\n");
188
+ process.stderr.write("No key provided (pass --api-key, pipe it on stdin, or type it).\n");
147
189
  process.exitCode = 1;
148
190
  return;
149
191
  }
@@ -171,5 +213,5 @@ program.command("posts").description("List recent posts").option("--limit <n>",
171
213
  (opts, command) => withClient(command, (c) => cmdPosts(c, opts), ["id", "type", "status", "scheduledAt"])
172
214
  );
173
215
  program.command("get <id>").description("Get one post by id").action((id, _opts, command) => withClient(command, (c) => cmdGet(c, id)));
174
- program.command("delete <id>").description("Delete a draft or cancel a scheduled post").option("--yes", "skip confirmation").action((id, opts, command) => withClient(command, (c) => cmdDelete(c, id)));
216
+ program.command("delete <id>").description("Delete a draft or cancel a scheduled post").action((id, _opts, command) => withClient(command, (c) => cmdDelete(c, id)));
175
217
  program.parseAsync(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anaella/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Command-line tool for anaella.com — schedule and publish social posts.",
5
5
  "type": "module",
6
6
  "bin": { "anaella": "dist/index.js" },