Skip to content

Commit

Permalink
feat: Support use as a package
Browse files Browse the repository at this point in the history
  • Loading branch information
dploeger committed Jan 23, 2024
1 parent 1ebc2d5 commit b1a8dbd
Show file tree
Hide file tree
Showing 22 changed files with 56 additions and 20 deletions.
4 changes: 2 additions & 2 deletions cmd/icarus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"fmt"
"github.com/akamensky/argparse"
"github.com/dploeger/icarus/pkg/outputTypes"
"github.com/dploeger/icarus/pkg/processors"
"github.com/emersion/go-ical"
"github.com/sirupsen/logrus"
"github.com/thoas/go-funk"
"icarus/pkg/outputTypes"
"icarus/pkg/processors"
"os"
"regexp"
"time"
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module icarus
module github.com/dploeger/icarus

go 1.19
go 1.21

require (
github.com/akamensky/argparse v1.4.0
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f
github.com/olekukonko/tablewriter v0.0.5
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.7.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
github.com/thoas/go-funk v0.9.3
)

Expand All @@ -17,5 +17,5 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/teambition/rrule-go v1.7.2 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/teambition/rrule-go v1.7.2 h1:goEajFWYydfCgavn2m/3w5U+1b3PGqPUHx/fFSVfTy0=
github.com/teambition/rrule-go v1.7.2/go.mod h1:mBJ1Ht5uboJ6jexKdNUJg2NcwP8uUMNvStWXlJD3MvU=
github.com/thoas/go-funk v0.9.3 h1:7+nAEx3kn5ZJcnDm2Bh23N2yOtweO14bi//dvRtgLpw=
Expand All @@ -26,5 +27,6 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 3 additions & 0 deletions pkg/outputTypes/ics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
)

// The ICSOutputType converts the internal calendar into the standardizes ICS format
type ICSOutputType struct{}

func (t *ICSOutputType) Initialize(_ *argparse.Parser) error {
Expand All @@ -23,3 +24,5 @@ func (t *ICSOutputType) Generate(calendar *ical.Calendar, writer io.Writer) erro
func (t *ICSOutputType) GetHelp() string {
return "outputs an ICS file from the processed calendar"
}

var _ BaseOutputType = &ICSOutputType{}
3 changes: 3 additions & 0 deletions pkg/outputTypes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
)

// The ListOutputType converts the internal calendar into a table format
type ListOutputType struct {
columns *[]string
}
Expand Down Expand Up @@ -43,3 +44,5 @@ func (t *ListOutputType) Generate(calendar *ical.Calendar, writer io.Writer) err
func (t *ListOutputType) GetHelp() string {
return "outputs a list of events from the processed calendar"
}

var _ BaseOutputType = &ListOutputType{}
3 changes: 3 additions & 0 deletions pkg/outputTypes/output_types.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package outputTypes includes all valid output types that Icarus supports.
// outputtypes use the internal processed calendar structure and format it for the output.
package outputTypes

import (
Expand All @@ -9,6 +11,7 @@ import (
"strings"
)

// The BaseOutputType is the basic interface for all output types
type BaseOutputType interface {
// Initialize can add arguments to the argument parser.
Initialize(parser *argparse.Parser) error
Expand Down
3 changes: 3 additions & 0 deletions pkg/processors/add_alarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"
)

// The AddAlarmProcessor adds an alarm definition to all selected events
type AddAlarmProcessor struct {
alarmBefore *int
toolbox Toolbox
Expand Down Expand Up @@ -38,3 +39,5 @@ func (a *AddAlarmProcessor) Process(input ical.Calendar, output *ical.Calendar)
}
return nil
}

var _ BaseProcessor = &AddAlarmProcessor{}
2 changes: 1 addition & 1 deletion pkg/processors/add_alarm_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package processors

import (
"github.com/dploeger/icarus/internal"
"github.com/emersion/go-ical"
"github.com/stretchr/testify/assert"
"icarus/internal"
"testing"
"time"
)
Expand Down
3 changes: 3 additions & 0 deletions pkg/processors/add_dtstamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"
)

// The AddDTStampProcessor adds a DTSTAMP field to all selected events
type AddDTStampProcessor struct {
timestamp *string
overwrite *bool
Expand Down Expand Up @@ -49,3 +50,5 @@ func (t *AddDTStampProcessor) Process(input ical.Calendar, output *ical.Calendar
}
return nil
}

var _ BaseProcessor = &AddDTStampProcessor{}
2 changes: 1 addition & 1 deletion pkg/processors/add_dtstamp_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package processors

import (
"github.com/dploeger/icarus/internal"
"github.com/emersion/go-ical"
"github.com/stretchr/testify/assert"
"icarus/internal"
"testing"
"time"
)
Expand Down
3 changes: 3 additions & 0 deletions pkg/processors/add_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
)

// The AddPropertyProcessor adds an ICS property to each selected event
type AddPropertyProcessor struct {
propertyName *string
propertyValue *string
Expand Down Expand Up @@ -50,3 +51,5 @@ func (a *AddPropertyProcessor) Process(input ical.Calendar, output *ical.Calenda
}
return nil
}

var _ BaseProcessor = &AddPropertyProcessor{}
2 changes: 1 addition & 1 deletion pkg/processors/add_property_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package processors

import (
"github.com/dploeger/icarus/internal"
"github.com/emersion/go-ical"
"github.com/stretchr/testify/assert"
"icarus/internal"
"testing"
)

Expand Down
3 changes: 3 additions & 0 deletions pkg/processors/convert_all_day.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"
)

// The ConvertAllDayProcessor converts all-day events to timed events or vice versa
type ConvertAllDayProcessor struct {
toolbox Toolbox
targetAllDay *bool
Expand Down Expand Up @@ -156,3 +157,5 @@ func (c *ConvertAllDayProcessor) getStartAndEndDuration() (time.Duration, time.D
}
return startDuration, endDuration, nil
}

var _ BaseProcessor = &ConvertAllDayProcessor{}
2 changes: 1 addition & 1 deletion pkg/processors/convert_all_day_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package processors

import (
"github.com/dploeger/icarus/internal"
"github.com/emersion/go-ical"
"github.com/stretchr/testify/assert"
"icarus/internal"
"testing"
"time"
)
Expand Down
3 changes: 3 additions & 0 deletions pkg/processors/delete_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
)

// The DeletePropertyProcessor deletes an ICS property from all selected events
type DeletePropertyProcessor struct {
propertyName *string
toolbox Toolbox
Expand Down Expand Up @@ -35,3 +36,5 @@ func (d *DeletePropertyProcessor) Process(input ical.Calendar, output *ical.Cale
}
return nil
}

var _ BaseProcessor = &DeletePropertyProcessor{}
2 changes: 1 addition & 1 deletion pkg/processors/delete_property_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package processors

import (
"github.com/dploeger/icarus/internal"
"github.com/emersion/go-ical"
"github.com/stretchr/testify/assert"
"icarus/internal"
"testing"
)

Expand Down
3 changes: 3 additions & 0 deletions pkg/processors/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/emersion/go-ical"
)

// The FilterProcessor filters the calendar for selected events
type FilterProcessor struct {
toolbox Toolbox
inverse *bool
Expand Down Expand Up @@ -33,3 +34,5 @@ func (f *FilterProcessor) Process(inputCalendar ical.Calendar, outputCalendar *i
func (f *FilterProcessor) SetToolbox(toolbox Toolbox) {
f.toolbox = toolbox
}

var _ BaseProcessor = &FilterProcessor{}
2 changes: 1 addition & 1 deletion pkg/processors/filter_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package processors

import (
"github.com/dploeger/icarus/internal"
"github.com/emersion/go-ical"
"github.com/stretchr/testify/assert"
_ "github.com/stretchr/testify/assert"
"icarus/internal"
"regexp"
"testing"
)
Expand Down
3 changes: 3 additions & 0 deletions pkg/processors/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/emersion/go-ical"
)

// The PrintProcessor simply outputs the input calendar
type PrintProcessor struct {
toolbox Toolbox
}
Expand All @@ -24,3 +25,5 @@ func (f *PrintProcessor) Process(inputCalendar ical.Calendar, outputCalendar *ic
func (f *PrintProcessor) SetToolbox(toolbox Toolbox) {
f.toolbox = toolbox
}

var _ BaseProcessor = &PrintProcessor{}
5 changes: 5 additions & 0 deletions pkg/processors/processors.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// Package processors includes all calendar processors available in Icarus.
//
// Icarus parses the incoming calendar data, hands it over to the processor to process data in it and
// formats the resulting data using an output type
package processors

import (
"github.com/akamensky/argparse"
"github.com/emersion/go-ical"
)

// The BaseProcessor is the interface for all Icarus processors
type BaseProcessor interface {
// Initialize creates a new subcommand for the argparse parser.
Initialize(parser *argparse.Parser) (*argparse.Command, error)
Expand Down
3 changes: 1 addition & 2 deletions pkg/processors/toolbox.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package processors

// a toolbox of common functions

import (
"github.com/emersion/go-ical"
"github.com/sirupsen/logrus"
"regexp"
"time"
)

// A Toolbox of common functions
type Toolbox struct {
// TextSelectorPattern is the user specified regexp pattern to select events by
TextSelectorPattern *regexp.Regexp
Expand Down
2 changes: 1 addition & 1 deletion pkg/processors/toolbox_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package processors

import (
"github.com/dploeger/icarus/internal"
"github.com/emersion/go-ical"
"github.com/stretchr/testify/assert"
"icarus/internal"
"regexp"
"testing"
"time"
Expand Down

0 comments on commit b1a8dbd

Please sign in to comment.