-
Notifications
You must be signed in to change notification settings - Fork 2
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 #1 from aj3sh/ad2bs-bs2ad
feat: combine ad2bs and bs2ad in one project
- Loading branch information
Showing
20 changed files
with
322 additions
and
576 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 |
---|---|---|
@@ -1,44 +1,27 @@ | ||
name: CI | ||
name: Github CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
branches: ['main'] | ||
pull_request: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
lint: | ||
ci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.21' | ||
- uses: golangci/golangci-lint-action@c67416616c29c3c48d26b59c45cadb56966d80aa | ||
go-version: 1.22 | ||
|
||
- name: Lint Code | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
args: --timeout=5m | ||
test: | ||
runs-on: ubuntu-latest | ||
needs: lint | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.21 | ||
- run: go test -v ./... | ||
release: | ||
runs-on: ubuntu-latest | ||
needs: test | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21 | ||
- uses: sumanchapai/go-semantic-release-action@v1 | ||
with: | ||
pre-release-post-dry-cmd: "cp .version cmd/.version" | ||
files-to-commit: "cmd/.version" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build | ||
run: make build | ||
|
||
- name: Test | ||
run: make test |
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,30 @@ | ||
name: "Release" | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
|
||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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,2 @@ | ||
dist/ | ||
.DS_Store |
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,30 @@ | ||
project_name: ad2bs | ||
release: | ||
github: | ||
owner: opensource-nepal | ||
name: ad2bs | ||
|
||
builds: | ||
- id: ad2bs | ||
main: cmd/ad2bs/main.go | ||
binary: ad2bs | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
- id: bs2ad | ||
main: cmd/bs2ad/main.go | ||
binary: bs2ad | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
|
||
nfpms: | ||
- id: ad2bs | ||
license: GPL-3.0 | ||
maintainer: Ajesh Sen Thapa<[email protected]> | ||
formats: | ||
- deb | ||
- rpm | ||
bindir: /usr/local/bin |
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,9 @@ | ||
# How to Contribute | ||
|
||
## Development Steps | ||
|
||
### Download the Dependencies | ||
|
||
```bash | ||
make go-get | ||
``` |
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,16 @@ | ||
build: | ||
go build -o dist/ad2bs cmd/ad2bs/main.go | ||
go build -o dist/bs2ad cmd/bs2ad/main.go | ||
|
||
test: | ||
go test -v ./... | ||
|
||
# Go specific make commands | ||
|
||
go-get: | ||
go get ./... | ||
|
||
go-clean: | ||
go clean -cache -modcache | ||
|
||
.PHONY: build test go-get go-clean |
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,17 +1,29 @@ | ||
Convert a given AD date in the format YYYY-MM-DD to BS date in the same format. | ||
# ad2bs | ||
|
||
To convert your birthday on 1999-10-29 AD to nepali, run\ | ||
`ad2bs 1999-10-29` | ||
Converts a given AD date to BS date and BS date to AD. | ||
|
||
## Installing / Updating `ad2bs` | ||
## Usage | ||
|
||
### If you have go installed. | ||
**Converting AD to BS** | ||
|
||
Have go >= 1.21 installed. Clone the repo, then run `go install .` | ||
```bash | ||
ad2bs YYYY-MM-DD | ||
``` | ||
|
||
**Converting BS to AD** | ||
|
||
```bash | ||
bs2ad YYYY-MM-DD | ||
``` | ||
|
||
Example: | ||
|
||
```bash | ||
ad2bs 1999-10-29 | ||
``` | ||
|
||
### If you don't have go installed, for macOS/Linux: | ||
## Installation | ||
|
||
```sh | ||
rm -f `which ad2bs` | ||
curl -s https://raw.githubusercontent.com/opensource-nepal/ad2bs/main/scripts/install.txt | sh | ||
curl -s https://raw.githubusercontent.com/aj3sh/ad2bs/main/scripts/install.sh | sh | ||
``` |
This file was deleted.
Oops, something went wrong.
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,51 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/opensource-nepal/go-nepali/nepalitime" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
ErrDateArgsMissing = errors.New("date argument is missing. format: YYYY-MM-DD") | ||
DateInputFormat = "2006-1-2" | ||
) | ||
|
||
func validateArgs(cmd *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
return ErrDateArgsMissing | ||
} | ||
_, err := time.Parse(DateInputFormat, args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func convertADToBS(cmd *cobra.Command, args []string) { | ||
enTime, _ := time.Parse(DateInputFormat, args[0]) | ||
npTime, err := nepalitime.FromEnglishTime(enTime) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: %v\n", err) | ||
return | ||
} | ||
npTimeFormat, _ := npTime.Format("%Y-%m-%d") | ||
fmt.Println(npTimeFormat) | ||
} | ||
|
||
func main() { | ||
var ad2bsCmd = &cobra.Command{ | ||
Use: "ad2bs", | ||
Short: "Convert AD date to BS", | ||
Args: validateArgs, | ||
Run: convertADToBS, | ||
} | ||
|
||
if err := ad2bsCmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
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,46 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/opensource-nepal/go-nepali/nepalitime" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
ErrDateArgsMissing = errors.New("date argument is missing. format: YYYY-MM-DD") | ||
DateOutputFormat = "2006-01-02" | ||
) | ||
|
||
func validateArgs(cmd *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
return ErrDateArgsMissing | ||
} | ||
_, err := nepalitime.Parse(args[0], "%Y-%m-%d") | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func convertBSToAD(cmd *cobra.Command, args []string) { | ||
npTime, _ := nepalitime.Parse(args[0], "%Y-%m-%d") | ||
enTime := npTime.GetEnglishTime() | ||
enTimeFormat := enTime.Format(DateOutputFormat) | ||
fmt.Println(enTimeFormat) | ||
} | ||
|
||
func main() { | ||
var bs2adCmd = &cobra.Command{ | ||
Use: "bs2ad", | ||
Short: "Convert BS to AD", | ||
Args: validateArgs, | ||
Run: convertBSToAD, | ||
} | ||
|
||
if err := bs2adCmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,10 +1,13 @@ | ||
module github.com/opensource-nepal/ad2bs | ||
module opensource-nepal/ad2bs | ||
|
||
go 1.21.7 | ||
go 1.22.1 | ||
|
||
require ( | ||
github.com/opensource-nepal/go-nepali v0.2.1 | ||
github.com/spf13/cobra v1.8.0 | ||
) | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/opensource-nepal/go-nepali v0.2.1 // indirect | ||
github.com/spf13/cobra v1.8.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
Oops, something went wrong.