Skip to content

Commit

Permalink
feat: conditional verbose errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfreud committed Apr 24, 2024
1 parent 88b0a10 commit b335db2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 40 deletions.
19 changes: 6 additions & 13 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@

- Replace OctokitResponse<any> by proper typing!
- Consider writing tests (unit tests and whatnot)
- Add warning about gitbub's rate limit
- Changeset to major version when basic cli is active
- Octokit
- Check if user is authenticated
- Add warning about gitbub's rate limit (docs)
- Add a mini logger lib file
- Handle verbose properly

## From feedback

- [x] use more branches (e.g. `main`, `develop`, `feature/...`, `bugfix/...`), moost of them will be temporary till reviewing process
- [x] see if owner can be retrieved from GitHub access token, use default as username
- [] better README
- [] donner plus d'infos pour l'access token, permettre d'obtenir un lien pour le générer avec peut-etre en query params de quoi remplir le formulaire avec le minimum requis pour l'access token
- [] preciser les permissions accordees a quirgo sont les permissions minimales requises
- [] donner la possibilite de stocker le token, voire meme plusieurs
- [] set verbose to false at default in configuration
- [ ] better README
- [ ] donner plus d'infos pour l'access token, permettre d'obtenir un lien pour le générer avec peut-etre en query params de quoi remplir le formulaire avec le minimum requis pour l'access token
- [ ] preciser les permissions accordees a quirgo sont les permissions minimales requises
- [ ] donner la possibilite de stocker le token, voire meme plusieurs
- [x] set verbose to false at default in configuration
- [x] mutual exclusion for options --json && --env
- [] simplify the usage of --verbose (specially when default is false)

-- CLI --
Other: [gulp, jest]
60 changes: 33 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,10 @@ import { KeyValueType } from "./types/parsers.js";

console.log(BANNER);

/**
* TODO: handle the case when --env/--json is provided
* TODO: create todolist in README.md
* TODO: doc -> note feature about default owner if -o not specified
*
*/

// Declare the program
const program = new Command();

function errorColor(str: string) {
// Add ANSI escape codes to display text in red.
return `\x1b[31m${str}\x1b[0m`;
}

program.configureOutput({
// Visibly override write routines as example!
// writeOut: (str) => process.stdout.write(`[OUT] ${str}`),
// writeErr: (str) => process.stdout.write(str),
// Highlight errors in color.
outputError: (str, write) => write(chalk.red(str)),
});

Expand Down Expand Up @@ -88,7 +72,10 @@ varsCommand
console.table(list?.data.variables);
console.log(chalk.bgGreen("Total: " + list?.data.total_count + " "));
} catch (err) {
console.error(chalk.red(err));
if (config.verbose) console.error(err);
console.error(
chalk.red("An error occured; please check the repository infos")
);
}
});
varsCommand
Expand All @@ -98,7 +85,10 @@ varsCommand
await fn();
await createVariableFn(config, repoManager, parsedKeyValues, name, value);
} catch (err) {
console.error(chalk.red(err));
if (config.verbose) console.error(err);
console.error(
chalk.red("An error occured; please check the repository infos")
);
}
})
.description("Create a new variable");
Expand All @@ -110,7 +100,10 @@ varsCommand
await fn();
await updateVariableFn(config, repoManager, parsedKeyValues, name, value);
} catch (err) {
console.error(chalk.red(err));
if (config.verbose) console.error(err);
console.error(
chalk.red("An error occured; please check the repository infos")
);
}
})
.description("Update an existing variable");
Expand All @@ -122,7 +115,10 @@ varsCommand
await fn();
await removeVariableFn(config, repoManager, parsedKeyValues, name);
} catch (err) {
console.error(chalk.red(err));
if (config.verbose) console.error(err);
console.error(
chalk.red("An error occured; please check the repository infos")
);
}
});

Expand Down Expand Up @@ -179,7 +175,10 @@ varsCommand.action(async () => {
break;
}
} catch (err) {
console.error(chalk.red(err));
if (config.verbose) console.error(err);
console.error(
chalk.red("An error occured; please check the repository infos")
);
}
});

Expand All @@ -200,9 +199,7 @@ secretsCommand
} catch (err) {
if (config.verbose) console.error(err);
console.error(
chalk.red(
"An error occured; please check the repository infos (owner & name)"
)
chalk.red("An error occured; please check the repository infos")
);
}
});
Expand All @@ -215,7 +212,10 @@ secretsCommand
await fn();
await setSecretFn(config, repoManager, parsedKeyValues, name, value);
} catch (err) {
console.error(chalk.red(err));
if (config.verbose) console.error(err);
console.error(
chalk.red("An error occured; please check the repository infos")
);
}
});

Expand All @@ -227,7 +227,10 @@ secretsCommand
await fn();
await removeSecretFn(config, repoManager, parsedKeyValues, name);
} catch (err) {
console.error(chalk.red(err));
if (config.verbose) console.error(err);
console.error(
chalk.red("An error occured; please check the repository infos")
);
}
});

Expand Down Expand Up @@ -266,7 +269,10 @@ secretsCommand.action(async () => {
break;
}
} catch (err) {
console.error(chalk.red(err));
if (config.verbose) console.error(err);
console.error(
chalk.red("An error occured; please check the repository infos")
);
}
});
program.hook("postAction", () => {
Expand Down

0 comments on commit b335db2

Please sign in to comment.