Code Monkey home page Code Monkey logo

gtodo's People

Contributors

heybran avatar priya1011 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

gtodo's Issues

Task ID bug

When listing tasks that belong to specific category or complete status, tasks IDs starts from 1 again, did not match with their original IDs, which will cause unexpected result if users try to delete tasks based on the IDs provided by list subcommand.

Bug:

After clone the repo in a new folder, delete the .todos.json file in my home directory, build the binary with GOOS=darwin GOARCH=amd64 go build -o todo cmd/main.go, then run ./todo init or any other subcommands in terminal, there is this error in terminal:

2023/05/05 18:24:54 open /Users/brandon/.todos.json: no such file or directory

If I put back the .todos.json file, then init subcommand works again, so some codes are trying to open that file initially before any command is run.

Add data directory and store todos.json

Question

What about an user has already been using cli todo app for a while and they have todo list stored inside todos.json file, and later down the road, they need to upgrade the cli todo app to a higher version, will their data inside todos.json get lost?

Answers from AI

If users have already been using the CLI todo app and have data stored in their todos.json file, you should take care to preserve their data when they upgrade to a new version of the app.

One way to do this is to include a version number in the todos.json file and check it when the app starts up. If the version number in the file is older than the current version of the app, you can migrate the data to the new format.

Here's an example of how to do this:

  1. Define a Version struct that includes the version number of the app and the version number of the todos.json file:

    type Version struct {
        AppVersion    string `json:"app_version"`
        DataVersion   string `json:"data_version"`
    }
  2. When the app starts up, read the todos.json file and check the version number:

    func main() {
        // Read the contents of the todos.json file from the data directory
        data, err := ioutil.ReadFile("data/todos.json")
        if err != nil {
            fmt.Println("Error reading todos.json:", err)
            return
        }
    
        // Unmarshal the JSON data into a Version struct
        var version Version
        err = json.Unmarshal(data, &version)
        if err != nil {
            fmt.Println("Error unmarshaling todos.json:", err)
            return
        }
    
        // Check the version number and migrate the data if necessary
        if version.DataVersion < "2.0.0" {
            migrateData()
        }
    
        // Unmarshal the JSON data into a slice of Todo structs
        var todos []Todo
        err = json.Unmarshal(data, &todos)
        if err != nil {
            fmt.Println("Error unmarshaling todos.json:", err)
            return
        }
    
        // Do something with the todos...
    }

    In this example, we first unmarshal the JSON data into a Version struct and check the DataVersion field. If the version number is older than 2.0.0, we call a migrateData function to migrate the data to the new format.

  3. Define a migrateData function that migrates the data to the new format:

    func migrateData() {
        // Read the contents of the todos.json file from the data directory
        data, err := ioutil.ReadFile("data/todos.json")
        if err != nil {
            fmt.Println("Error reading todos.json:", err)
            return
        }
    
        // Unmarshal the JSON data into a slice of old Todo structs
        var oldTodos []OldTodo
        err = json.Unmarshal(data, &oldTodos)
        if err != nil {
            fmt.Println("Error unmarshaling todos.json:", err)
            return
        }
    
        // Migrate the data to the new format
        var newTodos []Todo
        for _, oldTodo := range oldTodos {
            newTodo := Todo{
                Title: oldTodo.Title,
                Done:  oldTodo.Done,
            }
            newTodos = append(newTodos, newTodo)
        }
    
        // Marshal the new data to JSON and write it back to the todos.json file
        newData, err := json.Marshal(newTodos)
        if err != nil {
            fmt.Println("Error marshaling new data:", err)
            return
        }
        err = ioutil.WriteFile("data/todos.json", newData, 0644)
        if err != nil {
            fmt.Println("Error writing new data:", err)
            return
        }
    
        fmt.Println("Data migrated to new format.")
    }

Add --cat flag support to list subcommand

As todo task grows, we might want to list tasks that belong to specific category, so need to add --cat flag support to list subcommand so we can run:

gtodo list --cat "Job Search"

Add a release workflow

Need a release workflow.

  1. New version can be pushed to homebrew
  2. Also build out binaries for different operating systems.

Add init subcommand

Add an init subcommand to allow users to create an empty .todos.json file for storing their todo tasks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.