-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boosting CLI Capabilities: New options and robust configuration in main module #11
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set this parameter to false will make the function to set the unspecified or null options to undefined instead the default value. Additionally, the `resolveOptions` are now exported to ease the internal development.
For easier code maintenance within internal project.
This module is useful to parse command-line options.
This function will perform filtering and resolving given options from command-line argument parser and returns a read-only object with the processed and filtered options.
Fixed ESLint error for rule: no-extra-boolean-cast
* Removed unnecessary escape on regular expression * Disabled error for camelcase and prefer-const rules for specific code * Changed the double quotes to single quote strings
* Added new option to argument parser with options as following: - '-c' - '--config' * Implemented a new function called `resolveConfig` to resolve and parse the configuration file along with the documentation * Added a typedef called `YTMP3_Config` used for references of the configuration file * Removed the `getInput()` function from main module
All code within block `if (require,main === module)` has been reallocated to main function and refactored.
* Added `isNullOrUndefined` function to check whether the given value is null or undefined * Added `isObject` function to check whether the given value is an object and not null, an array, a `RegExp` instance, neither a URL instance
I'd forgot to export them on 84be5b0
* Introduced a new module named `config.js` offering the configuration resolver and parser * Added `parseConfig` function to import and parse the configuration file with support both JSON and JS file * Added `configChecker` function to check and validate the configuration object and throw an error if specific condition is met * Added an alias named `importConfig` that aliased from `parseConfig` function with `resolve` argument set to true * Moved the `resolveConfig` from main module to `config` module and refactored it to supports current module environments
Changed the visibility of two typedefs (`DownloadOptions` and `ConvertAudioOptions`) to global.
This helper function easily removes `null` and `undefined` properties from an object, useful for removing unnecessary properties from an object.
The option was implemented on change `714235c` but it was not handled properly. So, this change we added to resolve and parse the configuration file along with the documentation, including defined a typedef `FilteredOptions` and removed the `YTMP3_Config` typedef (which is now are defined in `lib/config` module).
This option to show the configuration that being used during download and audio conversion process. Useful for debugging.
* Fixed the logic on if statements due to unresolved null `url` * Added a warning message when user provide multiple URLs in a single command (`ytmp3 <url1> <url2> <url3>`). Because we still developing this feature of multiple downloads using URLs * Display the stack error if an error occurred on main function, this improving readability and make it easier to troubleshoot the problem * Minor refinement to the top-level module documentation
My bad, forgot to run lint first before pushing branch
mitsuki31
added a commit
that referenced
this pull request
Jul 24, 2024
Users can now supply multiple YouTube URLs in command line arguments without having to create a temporary file containing those URLs. This change gives more further flexibility and convenience for CLI-based users. For instance: $ ytmp3 -o downloads --convertAudio --codec libmp3lame --format mp3 \ > https://www.youtube.com/watch?v=<VIDEO_ID> https://www.youtube.com/watch?v=<VIDEO_ID> Resolves #11 task.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This pull request introduces a series of enhancements, and new features aimed at improving the command-line (CLI) functionality, maintainability, and usability of the main module and related components. The changes include the addition of new helper functions, configuration parsing capabilities, and enhancements to the argument parsing and main function logic, and also introduced new command-line options for easier configuring both download and audio conversion process instead using the programmatic way. See the supported and available options on Description section below.
Description
New Features
Command Line Argument Parsing
Introduced a new function,
initParser
, to handle various command-line arguments more efficiently, this function relying toargparse
module. Added afilterOptions
function to process and resolve command-line arguments, returning a read-only object with the filtered options. The supported command-line options are as follows:Download Options
--cwd
DIR
DIR
, used to resolve theoutDir
path. Defaults to the curent directory.-f
|--file
|--batch
FILE
-c
|--config
FILE
downloadOptions
object to configure both the download options and audio converter options.-o
|--outDir
|--out-dir
DIR
-C
|--convertAudio
|--convert-audio
-q
|--quiet
-qq
) to also suppress the audio conversion progress.Audio Converter Options
--format
FMT
--convertAudio
option.--codec
|--encoding
CODEC
--convertAudio
option.--bitrate
N
--convertAudio
option.--freq
|--frequency
N
--convertAudio
option.--channels
N
--convertAudio
option.--deleteOld
|--delete-old
|--overwrite
--convertAudio
option.Miscellaneous Options
-h
|-?
|--help
-V
|--version
-VV
) to also display all dependencies' version (not includingdevDependencies
).--copyright
--print-config
Configuration Resolving
Added a new module called
config
withinlib
directory, which offer some useful functions to parse and resolve configuration files.resolveConfig
Added a
resolveConfig
internal function to parse and resolve configuration files, supporting both JSON and JS formats.parseConfig
Introduced a
parseConfig
internal function that can handle both synchronous and asynchronous imports, along with aconfigChecker
function for validation.Helper Functions Addition
Added utility functions
isNullOrUndefined
,isObject
, anddropNullAndUndefined
to check types and clean objects. These functions are now exported fromutils
module for broader usage.Add Main Function
Consolidates the main code block into a driver function for improved readability and maintainability.
Feature Enhancements
resolveOptions
EnhancementsAdded a
useDefault
parameter to theresolveOptions
function. Setting this parameter tofalse
ensures that unspecified ornull
options are set toundefined
instead of their default values. The function is now exported for easier internal development.Dependency Addition
argparse
DependencyIncludes the
argparse
module for robust command-line argument parsing.Documentation
Typedef Visibility
Changed the visibility of
DownloadOptions
andConvertAudioOptions
typedefs to global for improved documentation clarity.Function Documentation
Provided detailed documentation for new and modified functions, including examples and parameter descriptions.
Todo List
Summary
This pull request refines the main module's structure and functionality, enhancing both the developer and user experience. Key improvements include more robust configuration handling, clearer argument parsing, addition of helpful utility functions, and the introduction of new command-line options. These changes lay the groundwork for future enhancements and ensure the module is more maintainable and easier to use.