-
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.
Signed-off-by: Rodolfo Sanchez <[email protected]>
- Loading branch information
Showing
7 changed files
with
210 additions
and
90 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
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,45 @@ | ||
/* | ||
Copyright © 2024 Rodolfo Sanchez <[email protected]> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
package aoctl | ||
|
||
import ( | ||
"github.com/dolfolife/aoctl/pkg/aoc" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var sessionCmd = &cobra.Command{ | ||
Use: "session", | ||
Aliases: []string{"initialize"}, | ||
Short: "Initialize the Advent of Code project in the path specifed", | ||
Args: cobra.ExactArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
session := cmd.Flags().Lookup("session").Value.String() | ||
|
||
aoc.SetSessionId(session) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(sessionCmd) | ||
|
||
sessionCmd.Flags().StringP("session", "s", "", "Session Cookie from the Advent of Code site") | ||
} |
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,26 @@ | ||
## How to Guides | ||
|
||
These are easy to follow guides to solve an specific problem you might have. | ||
|
||
### Start a new project | ||
|
||
In this guide we will create a new project and add your first solution for a [Advent of Code](https://adventofcode.com/) site. | ||
|
||
#### Initialize the project | ||
|
||
To start a new working folder for advent of code use the command [`init`](https://github.com/dolfolife/aoctl?tab=readme-ov-file#init). | ||
|
||
> By default it will create a new folder named `adventofcode` but you can change that with the parameter `--path` to initialize the project with a specific name. | ||
```bash | ||
aoctl init -p aoc-solutions | ||
``` | ||
|
||
Next, we need to add our user session to the project by editing the `.env` file. To fetch this user session you can check the `session` cookie in the cookies section of the browser inspect console. | ||
|
||
> The session cookie is a httpOnly cookie, so it can't be fetch using `document.cookie` object | ||
To add the session to the project use the `session` cmd | ||
|
||
```bash | ||
aoctl session -s <SESSION> | ||
``` |
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package aoc | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/joho/godotenv" | ||
) | ||
|
||
type AoCConfig struct { | ||
ProjectPath string | ||
SessionId string | ||
} | ||
|
||
func GetAoCConfig() AoCConfig { | ||
|
||
err := godotenv.Load() | ||
|
||
if err != nil { | ||
log.Fatal("error loading the .env file") | ||
} | ||
|
||
return AoCConfig{ | ||
SessionId: os.Getenv("AOC_SESSION"), | ||
ProjectPath: os.Getenv("PWD"), | ||
} | ||
} | ||
|
||
func SetSessionId(id string) { | ||
env, err := godotenv.Unmarshal(fmt.Sprintf("AOC_SESSION=%v", id)) | ||
|
||
if err != nil { | ||
log.Fatal("error writing the session into the environment") | ||
} | ||
|
||
err = godotenv.Write(env, "./.env") | ||
|
||
if err != nil { | ||
log.Fatal("error writing the session into the environment") | ||
} | ||
} |