Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: combine ad2bs and bs2ad in one project #1

Merged
merged 1 commit into from
May 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 16 additions & 33 deletions .github/workflows/ci.yml
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
30 changes: 30 additions & 0 deletions .github/workflows/release.yml
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 }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
.DS_Store
30 changes: 30 additions & 0 deletions .goreleaser.yaml
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<aj3sshh@gmail.com>
formats:
- deb
- rpm
bindir: /usr/local/bin
1 change: 0 additions & 1 deletion .version

This file was deleted.

9 changes: 9 additions & 0 deletions CONTRIBUTING.md
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
```
16 changes: 16 additions & 0 deletions Makefile
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
30 changes: 21 additions & 9 deletions README.md
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
```
1 change: 0 additions & 1 deletion cmd/.version

This file was deleted.

51 changes: 51 additions & 0 deletions cmd/ad2bs/main.go
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)
}
}
46 changes: 46 additions & 0 deletions cmd/bs2ad/main.go
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)
}
}
54 changes: 0 additions & 54 deletions cmd/root.go

This file was deleted.

23 changes: 0 additions & 23 deletions cmd/version.go

This file was deleted.

11 changes: 7 additions & 4 deletions go.mod
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
)
Loading