Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryG13 committed Jun 15, 2020
2 parents 086bad2 + 569fcd0 commit 12e4d13
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Executable (écrit en [Go](https://golang.org/)) pour convertir les fichiers exp
Par défaut, le script convertit les virgules (",") de sépration en point vigule de séparation (";"). Dans les textes longs, les caractères indésirables sont enlévés comme les caractères de saut de lignes et les points virgules.

## Usage
### Command line

Le package s'utilise en ligne de commande, en aucune dépendance, de la manière qui suit :

Expand All @@ -24,6 +25,12 @@ L'exécutable peut prendre en ligne de commande 4 arguments : 1 obligatoire et 3
- ```-sep ```: le caractère de séparation des données (par défaut ";")
- ```-uwc```: une liste (séparéé par des virgules) de caractère à enlever (en plus des caratèses de base)

### Interaction

Le package peut également être utilisé en mode interactif.

Si le chemin du fichier à traité n'est pas renseigné, il est alors demandé. Il suffit de le renseigner et d'appuyer sur entré pour lancer le processus.

## Téléchargement

Les versions précompilées sont téléchargeables dans la section "release" de la page ([ici](https://github.com/AmauryG13/airtable-convertor/releases)).
Expand Down
68 changes: 68 additions & 0 deletions cmd/airtable-convertor/lib/interation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package lib

import (
"fmt"
"os"
"path/filepath"
)

// Interaction is holding some var for creating interaction
type Interaction struct {
Input *os.File
Answer string
}

// NewInteraction is creating a new Interaction
func NewInteraction() *Interaction {
return &Interaction{
Input: os.Stdin,
}
}

// AskForInput is asking the user for a filename if it's not in func args
func (i *Interaction) AskForInput() string {
exePath, _ := os.Executable()
cwd := filepath.Dir(exePath)
fmt.Printf("Filepath is not filled in. Actual path : %q\n", cwd)
fmt.Println("Enter the path to file:")

var input string
fmt.Scanln(&input)
return filepath.Join(cwd, input)
}

// Notify is a commun func to log some actions taken by the script
func (i *Interaction) Notify(action string, args ...interface{}) {
switch action {
case "context":
i.printContext(args...)
case "start":
notifyStart(args...)
case "end":
notifyEnd(args...)
}
}

func (i *Interaction) printContext(args ...interface{}) {
list := (args[0]).([5]string)
argsValue := args[1:]
fmt.Println("------ Airtable Convertor")
fmt.Println("| Convertor called with arguments :")

for key := range list {
fmt.Printf("| - %s = %q\n", list[key], argsValue[key])
}

fmt.Println("******")
}

func notifyStart(args ...interface{}) {
filename := (args[0]).(string)
fmt.Printf("[Conversion started] File %q \n", filename)
}

func notifyEnd(args ...interface{}) {
filename := (args[0]).(string)
fmt.Printf("[Conversion terminated] File %q written\n", filename)
fmt.Println("------ Airtable Convertor")
}
17 changes: 14 additions & 3 deletions cmd/airtable-convertor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"os"
"strings"

"github.com/amauryg13/airtable-convertor-go/convertor"
"github.com/amauryg13/airtable-convertor/cmd/airtable-convertor/lib"
"github.com/amauryg13/airtable-convertor/convertor"
)

var fnUsage = func() {
Expand Down Expand Up @@ -36,21 +37,28 @@ var filepath string
var sep string
var eol string
var uwcFlag uwc
var help bool
var verbose bool

func init() {
flag.StringVar(&sep, "sep", ";", "Default record separator")
flag.StringVar(&eol, "eol", "\n", "Default end of line character")
flag.Var(&uwcFlag, "uwc", "Additional (comma separated) unwanted chars to removed")
flag.BoolVar(&help, "h", false, "Display help")
flag.BoolVar(&verbose, "v", false, "Display verbose debug info")
}

func main() {
interaction := lib.NewInteraction()

flag.Parse()

interaction.Notify("context", [5]string{"sep", "eol", "uwc", "help", "verbose"}, sep, eol, uwcFlag, help, verbose)

if flag.NArg() == 1 {
filepath = flag.Args()[0]
} else {
fnUsage()
os.Exit(1)
filepath = interaction.AskForInput()
}

removedChars := uwcFlag
Expand All @@ -60,5 +68,8 @@ func main() {
options["sep"] = sep

c := convertor.New(filepath, removedChars, options)

interaction.Notify("start", c.Input)
c.Run()
interaction.Notify("end", c.Output)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/amauryg13/airtable-convertor-go
module github.com/amauryg13/airtable-convertor

go 1.14

0 comments on commit 12e4d13

Please sign in to comment.