-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from seonggukchoi/release
- Loading branch information
Showing
10 changed files
with
73 additions
and
95 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ permissions: | |
|
||
jobs: | ||
release: | ||
name: release | ||
name: Release | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { DateCommand } from './date/date.command.js'; | ||
import { EncodeModule } from './encode/encode.module.js'; | ||
import { HashModule } from './hash/hash.module.js'; | ||
import { JwtModule } from './jwt/jwt.module.js'; | ||
import { OtpModule } from './otp/otp.module.js'; | ||
import { RandomModule } from './random/random.module.js'; | ||
import { SerializationModule } from './serialization/serialization.module.js'; | ||
|
||
@Module({ imports: [RandomModule, SerializationModule, JwtModule, HashModule, OtpModule, DateCommand] }) | ||
@Module({ imports: [RandomModule, EncodeModule, JwtModule, HashModule, OtpModule, DateCommand] }) | ||
export class AppModule {} |
3 changes: 2 additions & 1 deletion
3
...erialization-command-options.interface.ts → ...ncode/encode-command-options.interface.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { CopyableCommandOptions } from '../copyable/index.js'; | ||
|
||
export interface SerializationCommandOptions extends CopyableCommandOptions { | ||
export interface EncodeCommandOptions extends CopyableCommandOptions { | ||
decode?: boolean; | ||
base64?: boolean; | ||
hex?: boolean; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Command, Option } from 'nest-commander'; | ||
|
||
import { CopyableCommandRunner } from '../copyable/index.js'; | ||
|
||
import { EncodeCommandOptions } from './encode-command-options.interface.js'; | ||
|
||
@Command({ name: 'encode', description: 'Encode or decode the input.' }) | ||
export class EncodeCommand extends CopyableCommandRunner<EncodeCommandOptions> { | ||
public override async run(passedParams: string[], options?: EncodeCommandOptions | undefined): Promise<void> { | ||
if (!this.validateOptions(options)) { | ||
return; | ||
} | ||
|
||
if (options!.decode) { | ||
if (options!.base64) { | ||
this.print(Buffer.from(passedParams.at(0) ?? '', 'base64').toString(), options!.copy); | ||
} | ||
|
||
if (options!.hex) { | ||
this.print(Buffer.from(passedParams.at(0) ?? '', 'hex').toString(), options!.copy); | ||
} | ||
} else { | ||
if (options!.base64) { | ||
this.print(Buffer.from(passedParams.at(0) ?? '').toString('base64'), options!.copy); | ||
} | ||
|
||
if (options!.hex) { | ||
this.print(Buffer.from(passedParams.at(0) ?? '').toString('hex'), options!.copy); | ||
} | ||
} | ||
} | ||
|
||
@Option({ flags: '-d, --decode', description: 'Decode the input.' }) | ||
private applyDecodeOption(): boolean { | ||
return true; | ||
} | ||
|
||
@Option({ flags: '-b, --base64', description: 'Encode the input as base64.' }) | ||
private applyBase64Option(): boolean { | ||
return true; | ||
} | ||
|
||
@Option({ flags: '-x, --hex', description: 'Encode the input as hex.' }) | ||
private applyHexOption(): boolean { | ||
return true; | ||
} | ||
|
||
private validateOptions(options?: EncodeCommandOptions | undefined): boolean { | ||
if (!options) { | ||
return false; | ||
} | ||
|
||
if (options.base64 && options.hex) { | ||
this.print('The options cannot be used together.'); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { EncodeCommand } from './encode.command.js'; | ||
|
||
@Module({ providers: [EncodeCommand] }) | ||
export class EncodeModule {} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.