Giter VIP home page Giter VIP logo

Comments (7)

Timothee-Cardoso avatar Timothee-Cardoso commented on August 27, 2024

It's a strange thing

from secman.

abdfnx avatar abdfnx commented on August 27, 2024

to fix this bug, let's create an if statement, like this

if !IsUserAthenticated {
   return ":username"
}

from secman.

abdfnx avatar abdfnx commented on August 27, 2024

it's hard

from secman.

abdfnx avatar abdfnx commented on August 27, 2024

after many fixes and ideas, the final result is this

in tools/git_config/git_config.go

type ConfStruct struct {
	HttpClient func() (*http.Client, error)
	IO         *iostreams.IOStreams
	BaseRepo   func() (ghrepo.Interface, error)
}

func NewCmdConfigRoot(f *cmdutil.Factory) *cobra.Command {
	cmd := &cobra.Command{
		SilenceErrors: true,
		Run: func(cmd *cobra.Command, args []string) {},
	}

	cmd.SetOut(f.IOStreams.Out)
	cmd.SetErr(f.IOStreams.ErrOut)

	cmdutil.DisableAuthCheck(cmd)

	return cmd
}

func GitConfig(f *cmdutil.Factory, msg1 string, msg2 string) string {
	opts := ConfStruct{
		HttpClient: f.HttpClient,
	}

	httpClient, herr := opts.HttpClient()

	if herr != nil {
		return herr.Error()
	}

	apiClient := api.NewClientFromHTTP(httpClient)
	currentUser, _ := api.CurrentLoginName(apiClient, ghinstance.Default())
	
	cmdFactory := factory.New("x")
	configRootCmd := NewCmdConfigRoot(cmdFactory)
	cfg, _ := cmdFactory.Config()

	expandedArgs := []string{}

	if len(os.Args) > 0 {
		expandedArgs = os.Args[1:]
	}

	cmd, _, _ := configRootCmd.Traverse(expandedArgs)

	if cmdutil.IsAuthCheckEnabled(cmd) && !cmdutil.CheckAuth(cfg) {
		return msg1 + ":username" + msg2
	} else {
		return msg1 + currentUser + msg2
	}
}

from secman.

Timothee-Cardoso avatar Timothee-Cardoso commented on August 27, 2024

All this is just for the sake of this

if !IsUserAthenticated {
   return ":username"
}

from secman.

abdfnx avatar abdfnx commented on August 27, 2024

of course, and it's works

if the user was authenticated

open:       Open Your Private Repo (abdfnx/.secman).

if the user is wasn't authenticated

open:       Open Your Private Repo (:username/.secman).

from secman.

abdfnx avatar abdfnx commented on August 27, 2024

it's also for sync command

if the user was authenticated

clone:      Clone your .secman from your private repo at https://github.com/abdfnx/.secman .
pull:       Pull The New Passwords from abdfnx/.secman .
push:       Push The New Passwords in ~/.secman .
start:      Start Sync your passwords.

if the user is wasn't authenticated

clone:      Clone your .secman from your private repo at https://github.com/:username/.secman .
pull:       Pull The New Passwords from :username/.secman .
push:       Push The New Passwords in ~/.secman .
start:      Start Sync your passwords.

from secman.

Related Issues (20)

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.